|
-
Sep 8th, 2002, 05:24 PM
#1
Thread Starter
Frenzied Member
Calling Function In Exe
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 ?
-
Sep 8th, 2002, 05:28 PM
#2
Frenzied Member
You can. You just export your functions from the EXE the same way you would with a DLL.
Z.
-
Sep 8th, 2002, 08:15 PM
#3
Frenzied Member
Zaei -
I think he wants oemthing like sHell in VB -
Use the ShellExecute() api.
-
Sep 9th, 2002, 10:24 AM
#4
Thread Starter
Frenzied Member
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.
-
Sep 9th, 2002, 11:33 AM
#5
Do you use a custom entry point? Maybe have a corrupted CRT?
This is very strange...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 9th, 2002, 11:44 AM
#6
Thread Starter
Frenzied Member
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
Code:
#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);
}
The code in main.def
Code:
LIBRARY "Project2.exe"
EXPORTS
Hello
I pardon any crap C++ coding on mybehalf
-
Sep 9th, 2002, 03:06 PM
#7
Frenzied Member
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.
-
Sep 11th, 2002, 09:34 AM
#8
Junior Member
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.
Last edited by Techno-Logic; Sep 11th, 2002 at 09:37 AM.
-
Sep 11th, 2002, 09:38 AM
#9
But then you have problems using the import library with any other compiler than with which it was created.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 11th, 2002, 10:07 AM
#10
Thread Starter
Frenzied Member
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.
-
Sep 11th, 2002, 03:12 PM
#11
Frenzied Member
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.
-
Sep 12th, 2002, 07:23 AM
#12
PowerPoster
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
-
Sep 12th, 2002, 07:43 AM
#13
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.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 12th, 2002, 10:26 AM
#14
Frenzied Member
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.
-
Sep 12th, 2002, 11:24 AM
#15
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.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 12th, 2002, 11:33 AM
#16
Frenzied Member
That is what I figured =). Goodness it is nice to be able to figure this kind of stuff out =).
Z.
-
Sep 13th, 2002, 10:34 PM
#17
PowerPoster
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,
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.
-
Sep 13th, 2002, 11:08 PM
#18
Frenzied Member
Yes, you can use both together.
Z.
-
Sep 16th, 2002, 04:51 AM
#19
But it shouldn't be necessary as implicit linking should work with def files too.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|