Functions in a DLL...

Started by
5 comments, last by iNsAn1tY 20 years, 10 months ago
I'm currently writing *.3ds and *.obj model file loaders for my level editor. However, I have a problem: I'm writing the editor in VB (for the time being; MFC coming soon) and writing the loaders (along with a few other important functions) in nice, friendly C. I've put the loaders and other code in a DLL, but I'm having trouble linking to the functions. I tried Public Declare Function to no avail (error said it couldn't find my DLL, "core.dll"), then tried to use GetProcAddress(). This didn't work either (I didn't think it would; no pointers in VB). Before all this, I tried to load the DLL in the "References..." menu, but it couldn't be loaded. The DLL is properly formatted (although it doesn't have DllMain() function), and the functions are listed as EXPORTS in a *.def file. I've tried to load it with my C engine, and it loaded fine, and I could find all the functions. I've seen people mention that they use VB for the UI, and store the C renderer in a DLL. I'd like to have the DLL in the same directory as the program executable. I know there's probably a simple solution to this, but I've lost my MSDN disc . Thanks in advance for any replies...
Coding Stuff ->  [ iNsAn1tY Games | DarkVertex | How To Do CSG | Direct3D Vs. OpenGL | Google ]
Fun Stuff    ->  [ Evil T-Shirts | Stick-Based Comedy | You're Already Here | The Best Film Reviews ] [edited by - iNsAn1tY on June 16, 2003 4:01:57 PM]
My opinion is a recombination and regurgitation of the opinions of those around me. I bring nothing new to the table, and as such, can be safely ignored.[ Useful things - Firefox | GLee | Boost | DevIL ]
Advertisement
If you put the DLL in Windows\System it should be able to find it. Also, be careful with ByVal and ByRef in your declare statement, sometimes when you think it should be one way, it is actually another. For instance, Strings are actually ByVal.
You must use the __stdcall calling convention for all your exported function you want to call from within VB.

You can do this using one of two methods.

1. Tell your compiler to use __stdcall for all functions.

In Visual C++, goto Project->Settings, click on the C/C++ tab and select "Code Generation" in the category combo box, then select __stdcall for the calling convention.

2. Comtinue to use the default __cdecl calling convention and use __stdcall for your exported library functions.

Best way to implement this is to define the calling convention and use this were necessary...
#define MYDLLAPI __stdcallvoid MYDLLAPI MyExportedFunction(void){}


I hope this helps ;-)

- Kevin

[edited by - moNoKnoT on June 17, 2003 2:18:17 PM]
http://www.kevin-fell.co.uk
Thanks for the replies. I've finished most of the C functions I need for my map editor, and now all I need to do is put them in the DLL. Sailorstick, I'll put my DLL in c:\Windows\System for the time being, but I'd still like to have it in the same directory as the executable. Anyone got any idea whether this is possible? If it's not, I'll just wait until I write the C++/MFC version of my editor. moNoKnoT, thanks for the heads-up on the __stdcall stuff...


Coding Stuff ->  [ iNsAn1tY Games | DarkVertex | How To Do CSG | Direct3D Vs. OpenGL | Google ]
Fun Stuff    ->  [ Evil T-Shirts | Stick-Based Comedy | You're Already Here | The Best Film Reviews ]

[edited by - iNsAn1tY on June 25, 2003 7:27:02 AM]
My opinion is a recombination and regurgitation of the opinions of those around me. I bring nothing new to the table, and as such, can be safely ignored.[ Useful things - Firefox | GLee | Boost | DevIL ]

http://msdn.microsoft.com/

online msdn
It should look for the Dll in the same directory as the exe file first by default.
I am pretty sure it should work to have the DLL in the same dir as the exe, when you have compiled it to an exefile.
When running from the editor you should place it in Windows\System.

Cheers!

My game: Swift blocks
DISCLAIMER: If any of the above statements are incorrect, feel free to deliver me a good hard slap!My games: DracMan | Swift blocks

This topic is closed to new replies.

Advertisement