|
-
July 10th, 2006, 02:37 AM
#1
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.
-
July 10th, 2006, 03:27 AM
#2
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
-
July 10th, 2006, 03:42 AM
#3
Re: DLL's Compatibility
 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
-
July 10th, 2006, 04:26 AM
#4
Re: DLL's Compatibility
Hi..,
I have tried both of the above mentioned ideas..but it is still giving the same problem.
-
July 10th, 2006, 05:11 AM
#5
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
-
July 10th, 2006, 05:39 AM
#6
Re: DLL's Compatibility
Hi,
My function signature lokks like below...
CRF_U_API int __cdecl POn_CRF(char * sR);
-
July 10th, 2006, 05:43 AM
#7
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
-
July 10th, 2006, 05:48 AM
#8
Re: DLL's Compatibility
If i use __stdcall will it work in VC++?
-
July 10th, 2006, 05:54 AM
#9
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
-
July 10th, 2006, 08:00 AM
#10
Re: DLL's Compatibility
Hello Krishnaa,
My program is working..thanks
Thanks & Regards,
Poornima.
-
July 10th, 2006, 09:05 AM
#11
Re: DLL's Compatibility
Good !
-
July 12th, 2006, 05:01 AM
#12
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.
-
July 12th, 2006, 05:11 AM
#13
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
-
July 12th, 2006, 05:19 AM
#14
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.
-
July 12th, 2006, 05:28 AM
#15
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|