From: Jiri K. <jirikrivanek@BetaControl.cz> - 2003-01-28 07:55:20
|
> Hi Jiri, > > > "Jiri Krivanek" <jirikrivanek@BetaControl.cz> writes: > > How can I call the Mul() export of the KK.DLL? Please, do not advice > > me to use the LoadLibrary() and the GetProcAddress() Windows APIs. > > There must be some other possibility. > > The quickest solution way is just adding the DLL to your link-line. I > just created these files to check: > > >>>>>>>>>>>>> kkh.h > #ifndef KKH > #define KKH > > extern int Mul(int a, int b); > > #endif // KKH > <<<<<<<<<<<<< > > >>>>>>>>>>>>> kkh.c > #include "kkh.h" > > extern int __declspec(dllexport) > Mul(int a, int b) > { > return a*b; > } > <<<<<<<<<<<<< > > >>>>>>>>>>>>> kkh-user.c > #include <stdio.h> > #include "kkh.h" > > extern int > main() > { > printf( "2*2=%d\n", Mul(2,2) ); > return 0; > } > <<<<<<<<<<<<< > > With these files these command-lines worked: > > c:\tmp> gcc -shared -o kkh.dll kkh.c > c:\tmp> gcc -o kkh-user.exe kkh-user.c kkh.dll > c:\tmp> kkh-user > 2*2=4 > > > Another way to do it is to create import libraries for the DLLs in > question. The w32api sources have examples how to do that, see the SF > download page (get there from http://sourceforge.net/projects/mingw). > > > Hope this helps, benny > > Hello, thanx for your advices. I tried to and the elementary example works fine. But my problem is a bit different. The DLL I want to call in my program is not written by me, I have no sources of it and it even was not compiled by the gcc. When I use the above mentioned technique, I receive the following linker error message (please note that this is only one of many): ...:main.c: undefined reference to 'GdipDeletePen@4' If I understand well, this means that the LD linker is looking for a function named 'GdipDeletePen@4' (the @4 might mean the size of stack required for parameters ???) but in the given gdiplus.dll there is no such export. If I simply look into the binary image of the gdiplus.dll I will locate the string 'GdipDeletePen' instead. This means that I have to make the compiler not to append the @<xx> characters to (at least some certain) external names. Well I am going to scan through the compilers command line options (to avoid appending @<xx> globally) as well as consult the gcc manual (to avoid appending @<xx> for some certain externals only). Thank you all for helphing me & best regards, Kk. Ing. Jiri Krivanek Realtime applications programmer Beta Control s.r.o. Cerneho 58/60 635 00 BRNO-Bystrc CZECH REPUBLIC tel.: +420 5 46 22 34 91 - 36 email 1: JiriKrivanek@BetaControl.cz |