Advertisement

Win32 DLL name crunching

Started by August 12, 2000 03:15 AM
2 comments, last by Lord Chaos 24 years, 4 months ago
When I try to create a DLL and export a function from it:
    
__declspec(dllexport) CeRenderDevice *CreateDevice(void);
[/source]

And then load the DLL in my main program with:

[source]
HMODULE hLib = LoadLibrary( szLib );
FARPROC pfCreate = GetProcAddress( hLib, "CreateDevice" );
    
I get errors. The LoadLibrary succeeds, giving me a handle, but GetProcAddress fails with an error "The specified procedure could not be found". So, I check the .dll file with dumpbin /exports cedevice.dll and get this list:

File Type: DLL

  Section contains the following exports for cedevice.dll

           0 characteristics
    39950361 time date stamp Sat Aug 12 09:57:21 2000
        0.00 version
           1 ordinal base
           4 number of functions
           4 number of names

    ordinal hint RVA      name

          1    0 00001014 ?CreateDevice@@YAPAVCeRenderDevice@@XZ
          2    1 00033C40 ?nCeRenderDeviceMajorVersion@@3HA
          3    2 000359A8 ?nCeRenderDeviceMinorVersion@@3HA
          4    3 00033C44 ?szCeRenderDeviceName@@3PADA

  Summary

        5000 .data
        1000 .idata
        3000 .rdata
        2000 .reloc
       2F000 .text
Wtf! How do I tell VC++ to not mangle my exports to "?CreateDevice@@YAPAVCeRenderDevice@@XZ" and such things?
-------------------------------------------------------------LGPL 3D engine - http://www.sourceforge.net/projects/realityengine
Something messed up my source tags in the post, and now the forum won''t let me edit my post... anyway, nothing important was messed up, so you will be able to read it anyway, I hope. This is the error I got when trying to edit:

ADODB.Field error ''800a0bcd''

Either BOF or EOF is True, or the current record has been deleted; the operation requested by the application requires a current record.

/community/forums/post.asp, line 105
-------------------------------------------------------------LGPL 3D engine - http://www.sourceforge.net/projects/realityengine
Advertisement
Either compile a file with a .c extension, or surround anything you don''t want to be named in C++ style with...

extern "C"
{
}
Use a .def file. Then you can export the function with the exact name you want rather than the mangled name. I think even if you use extern "C" you''ll get a slightly mangled version.

This topic is closed to new replies.

Advertisement