May 04, 2006
Hi, I'm sure I am being stupid here...

I'm compiling a DLL from a file test.c

=================================================
SOURCE FOR test.c
=================================================
#include <windows.h>

__declspec(dllexport) double WINAPI Test ( void ) {
return 4.0;
}


BOOL WINAPI DllMain(
HINSTANCE hinstDLL,
DWORD fdwReason,
LPVOID lpvReserved
) {
}
=================================================

test.c is compiled with the command
dmc -mn -WD test.c kernel32.lib

This dll is called by another file with source test2.c

=================================================
SOURCE for test2.c
=================================================
#include <windows.h>
#include <stdio.h>

typedef double (WINAPI *doubleVoidProc)(void);

int main (int argc, char *argv[]) {
HMODULE h;
doubleVoidProc funcPtr;

printf("Loading DLL.. ");
h = LoadLibrary("test.dll");
if (!h) {
printf("Failed\n");
exit(1);
}
else
printf("OK\n");

funcPtr = (doubleVoidProc) GetProcAddress( h, "Test" );
if (!funcPtr) {
printf("Function not found\n");
exit(1);
}
printf("Function value %d\n", funcPtr());
FreeLibrary(h);

return 0;
}
=================================================

test2.c is compiled with the command
dmc test2.c

Despite the __declspec(dllexport) in test.c, the Test function does not get exported unless I manually add the lines

EXPORT
Test

to the test.def file.

What am I doing wrong?

Cheers,

Simon


May 04, 2006
Simon McGregor wrote:

I'm not an DLL expert, but

> =================================================
> SOURCE FOR test.c
> =================================================
> #include <windows.h>
> 
> __declspec(dllexport) double WINAPI Test ( void ) { 

Try to remove th WINAPI here

> return 4.0;
> }
> 
[snip]
> 
> typedef double (WINAPI *doubleVoidProc)(void);

And here

> 
> int main (int argc, char *argv[]) {
> HMODULE h;
> doubleVoidProc funcPtr;
> 
> printf("Function value %d\n", funcPtr());

And change that to %f (for double)

And it should work.

You can use the implib tool to create a import library,
which imho makes it easier to work with DLL's

There is a small guide here:
http://home20.inet.tele.dk/midgaard/tipwin20060212.html

-- 
Absolutely not the best homepage on the net:
http://home20.inet.tele.dk/midgaard
But it's mine - Bertel