hey,
I know that you can use LoadLibrary() and GetProcAddress() to load a function up from a .dll.
I have tried this but with using an exe instead although it doesnt work.
Is it possible ?
Printable View
hey,
I know that you can use LoadLibrary() and GetProcAddress() to load a function up from a .dll.
I have tried this but with using an exe instead although it doesnt work.
Is it possible ?
You can. You just export your functions from the EXE the same way you would with a DLL.
Z.
Zaei -
I think he wants oemthing like sHell in VB -
Use the ShellExecute() api.
okay Zaei, i tried that although it says this:
Debug/Project2.exe : warning LNK4086: entrypoint "_mainCRTStartup" is not __stdcall with 12 bytes of arguments; image may not run
it compiles (as its only a warning) although it doesnt run properly.
Do you use a custom entry point? Maybe have a corrupted CRT?
This is very strange...
I changed it to a normal windows app (non Console) and got this error:
Creating library Debug/Project2.lib and object Debug/Project2.exp
Debug/Project2.exe : warning LNK4086: entrypoint "_WinMainCRTStartup" is not __stdcall with 12 bytes of arguments; image may not run
The code in main.cpp
The code in main.defCode:
#include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
return 0;
}
void __declspec(dllexport) Hello (void)
{
MessageBox(NULL, "Hello", "Project2", MB_OK);
}
I pardon any crap C++ coding on mybehalf :DCode:
LIBRARY "Project2.exe"
EXPORTS
Hello
Alrighty, here is the deal. The compiler is reading your .def file, and exporting all of the functions in there. Fine. Unfortunatly, it does NOT export the exe entry point, thus, well, no entry point. I tried adding it to the def file, but it complains about an unresolved external symbol, and such. What you acn do instad is use the dependency viewer on your exe (depends.exe, comes with VS), and find out the mangled names of the functions you export, and use THOSE names when calling LoadLibrary().
Z.
As far as I know, if you declare a function with __declspec(dllexport) keyword, you don`t need to write the function`s name in a *.def file, too.
Removing the main.def file may solve the problem.
But then you have problems using the import library with any other compiler than with which it was created.
This problem is now solved. i was wanting to call a function in a vb exe but this wasnt working so i tried a C++ one. neither worked and i knew because VB cant export a function. im now using different methods.
Thanks again for help.
CornedBee is correct. Without the .def file, the function will export, but it will shows up as its mangled name. The def file exports the function name UNmangled, and thus makes it a bit easier to use. If you are using implicit linking, this is a moot point, since only the compiler cares what the functions are called, but if you need to call the function from another language, using the def file makes things a bit easier.
Z.
Hi CornedBee and Zaei, Just a quick question. Can i have both the definition file (.def) and the export the function with __declspec(dllexport) syntax together?
So, my exported function can be access either through implicit or explicit link.
regards,
Chris
The __declspec(dllexport) is not necessary when you have a def file. It was invented by MS to make creating dlls that are only linked to implicitly easier. And to allow the exporting of classes.
Makes me wonder if you could use a C style member function call in VB with an exported class from a DLL... Something to try sometime =).
Z.
You can. Look up the mangled name, create a Type in VB that matches the classes internal data structure, have the first param of the function be ByRef this As ClassData and off you go.
The tricky thing of course is calling the constructor and destructor.
That is what I figured =). Goodness it is nice to be able to figure this kind of stuff out =).
Z.
yup, but can i have both together? 'coz i'm writing an SDK for others party to develop. If i have both together, then my user can either use my dll in implicit or explicit link.
regards,
Quote:
Originally posted by CornedBee
The __declspec(dllexport) is not necessary when you have a def file. It was invented by MS to make creating dlls that are only linked to implicitly easier. And to allow the exporting of classes.
Yes, you can use both together.
Z.
But it shouldn't be necessary as implicit linking should work with def files too.