From: Li W. <li_...@so...> - 2002-12-05 06:02:44
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"> <title></title> </head> <body> <br> <blockquote type="cite">How do i make a dll written in c and compiled in mingw to be interfaced from<br> Visual Basic ??????? I've already done this but doesnt work:</blockquote> <br> Let me see what's wrong here.<br> <blockquote type="cite">EXPORT unsigned char suma( unsigned char a, unsigned char b)<br> {<br> return a+b;<br> }<br> </blockquote> If you want Visual Basic to call this function, you must use stdcall, not ccall, so your <br> fuction must be declared like this:<br> <br> __stdcall unsigned char suma( unsigned char a, unsigned char b)<br> <br> Or, if you have include windows.h, you can use <br> WINAPI ,PASCAL . . . instead of __stdcall. Like this:<br> <br> WINAPI unsigned char suma( unsigned char a, unsigned char b)<br> <blockquote type="cite">#ifdef BUILD_DLL<br> // the dll exports<br> #define EXPORT __declspec(dllexport)<br> #else<br> // the exe imports<br> #define EXPORT __declspec(dllimport)<br> #endif<br> <br> EXPORT unsigned char suma ( unsigned char a, unsigned char b);</blockquote> Never use __declspec(dllexport) if you want it can be used anywhere.<br> then why? <br> 1. your must rebuild the caller application every time when the dll be changed.<br> 2. if you use __declspec(dllexport) and use stdcall, VB can not find the entry point <br> of the function, because the export function will be name as something <br> like suma@8 by compiler. except ,you declare the function name as <br> suma@8 in VB,would you like this? and you know if do not use stdcall ,VB can find<br> the entry point , but the paramerter check will failed. <br> <br> So make a def file instead of use __declspec(dllexport) . like this:<br> suma.def<br> <br> LIBRARY "suma"<br> DESCRIPTION 'The Suma Dynamic Link Library'<br> EXPORTS<br> suma @1<br> <br> Then compile use:<br> gcc -shared -o suma.dll suma.c suma.def<br> <br> Sorry for my poor english.<br> <br> <br> <em><b><i><font><span>Best Regards<br> </span></font></i></b></em>-------------------------------------------------------<br> Li Wenhao<br> Programmer, My friend like call me "Mouse"<br> So you can.<br> -------------------------------------------------------<br> </body> </html> |