CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Join Date
    Jun 2003
    Location
    Bangalore,INDIA
    Posts
    122

    DLL's Compatibility

    Hello,

    I have developed a DLL in VC++, i want to use it in VB and VB.net.. When i try to use the DLL in vb it is giving Bad DLL Calling Convention. I changed the Calling Convention to __stdcall from __cdecl* Code Generation option in C/C++ tab in Project Settings. I will be able to use the DLL compiled with __stdcall in VB but if i use the same DLL in VC++ againg, it will give error unresolved external symbol __imp__('Function Name'). Can anybody please help me..its urgent

    Thanks in advance,
    Poornima.

  2. #2
    Join Date
    Jan 2005
    Location
    germany
    Posts
    160

    Re: DLL's Compatibility

    if you declare a function _stdcall, VC will not have any problems calling it. ACtually: all win APIs are _stdcall, so ... there should not be a problem.

    just make sure, that the dll and the program consuming the dll use the same header.

    regards
    HoM

  3. #3
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: DLL's Compatibility

    Quote Originally Posted by cheery_poori
    Hello,

    I have developed a DLL in VC++, i want to use it in VB and VB.net.. When i try to use the DLL in vb it is giving Bad DLL Calling Convention. I changed the Calling Convention to __stdcall from __cdecl* Code Generation option in C/C++ tab in Project Settings. I will be able to use the DLL compiled with __stdcall in VB but if i use the same DLL in VC++ againg, it will give error unresolved external symbol __imp__('Function Name'). Can anybody please help me..its urgent

    Thanks in advance,
    Poornima.
    Try using
    Code:
    extern "C" __stdcall void MyExportedFunction()
    {
    }
    Regards,
    Ramkrishna Pawar

  4. #4
    Join Date
    Jun 2003
    Location
    Bangalore,INDIA
    Posts
    122

    Re: DLL's Compatibility

    Hi..,

    I have tried both of the above mentioned ideas..but it is still giving the same problem.

  5. #5
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: DLL's Compatibility

    Is the function signature ( like int myfunction(); ) added to the project where you are using it ?

    What is the function signature there ?
    Last edited by Krishnaa; July 10th, 2006 at 05:44 AM.
    Regards,
    Ramkrishna Pawar

  6. #6
    Join Date
    Jun 2003
    Location
    Bangalore,INDIA
    Posts
    122

    Re: DLL's Compatibility

    Hi,

    My function signature lokks like below...
    CRF_U_API int __cdecl POn_CRF(char * sR);

  7. #7
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: DLL's Compatibility

    But you have modified it in DLL to have __stdcall.

    The function signature has to be same everywhere (in DLL and where you use/call it).

    Make it as,
    Code:
    CRF_U_API int __stdcall POn_CRF(char * sR);
    Regards,
    Ramkrishna Pawar

  8. #8
    Join Date
    Jun 2003
    Location
    Bangalore,INDIA
    Posts
    122

    Re: DLL's Compatibility

    If i use __stdcall will it work in VC++?

  9. #9
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: DLL's Compatibility

    Yes.....

    __stdcall is just a calling convention, it not only for VB. VC++ (rather C/C++) programs understand a lot of other function calling conventions too but VB assumes external functions to be __stdcall.
    Regards,
    Ramkrishna Pawar

  10. #10
    Join Date
    Jun 2003
    Location
    Bangalore,INDIA
    Posts
    122

    Re: DLL's Compatibility

    Hello Krishnaa,

    My program is working..thanks

    Thanks & Regards,
    Poornima.

  11. #11
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: DLL's Compatibility

    Good !


  12. #12
    Join Date
    Jun 2003
    Location
    Bangalore,INDIA
    Posts
    122

    Re: DLL's Compatibility

    Hello Krishnaa,

    I have one more problem.. in my dll i am returning a char* array.., in vb i am not able to get this return parameter.. My function is as below...

    'Public CRF_U_API char * __stdcall GetCName( int CType );
    Public Declare Function GetCName Lib "Crf.dll" _
    (ByVal CType As Integer) As Byte

    Thanks & Regards,
    Poornima.

  13. #13
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: DLL's Compatibility

    Declare VB signature as
    Code:
    Public Declare Function GetCName Lib "Crf.dll" (ByVal CType As Integer) As String
    Regards,
    Ramkrishna Pawar

  14. #14
    Join Date
    Jun 2003
    Location
    Bangalore,INDIA
    Posts
    122

    Re: DLL's Compatibility

    Hello Krishnaa,

    I have tried using String as return parameter..but it gives 'memory could not read' error and abruptly closes my application.

    Thanks & Regards,
    Poornima.

  15. #15
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: DLL's Compatibility

    You will need to use BSTR as return type instead of Char* in VC DLL,
    like this,
    Code:
    CRF_U_API BSTR __stdcall GetCName( int CType );
    
    {
       char* lpszText = "Test";
       printf("char * text: %s\n", lpszText);
       BSTR bstrText = _com_util::ConvertStringToBSTR(lpszText);
       return bstrText ;
    }
    Regards,
    Ramkrishna Pawar

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured