Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Importing C functions and variables into a C++ dll

This topic is 6190 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I need some dll C/C++ windows experts here... Ok, here I go. My game is developed using PowerRender(http://www.powerrender.com) which is actually composed of several C static libraries. I want to get a OOP approach of my game (I actually need it for a SDK kind of game) so I went to C++ and Dll programming. So, I now have the following workspace : 1/ a win32 project 2/ a dll project that wraps PowerRender Libraries. The only problem I am getting is that PowerRender needs to get several variables that are on the win32 project (do not ask me why it is that way, it just is and you can''t get through). Let''s imagine the function I want to call from my win32 project is : void MyFunc(char* name). I tried several calls inside my dll : extern "C" void MyFunc(char* name); or __declspec(dllimport) void MyFunc(char* name) or extern "C" __declspec(dllimport) void MyFunc(char* name) noone of these calls worked... Would you give an hand ?;.. Thanks, Amadrias France

Share this post

Link to post
Share on other sites
As you already know, the following tells the DLL to *IMPORT* the symbol called MyFunc:

extern "C" __declspec(dllimport) void MyFunc(char* name)

The problem is, nothing is *EXPORTED* from your .exe!. Declare the function in the .exe (the Win32 project) as dllexport. Otherwise, when the DLL is loaded it''s looking for the symbol called MyFunc, but doesn''t know where to get it from.

You may still have problems with this though - a .DLL which needs to import symbols from a .EXE is very strange and very badly designed. I''m sure there''ll be another way.

A useful tool to see which symbols are imported and exported from DLLs and EXEs is "Dependency Walker". In MSVC you''ll find it called "Depends" under "Microsoft Visual Studio 6.0 Tools" in the MSVC program group from the Start menu.

Simon O''''Connor
Creative Asylum Ltd

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!