Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi All,
This is santosh,
While dealing dlls i load dll dynamically from user define folder all information related i got from this code project only.

now i want to call dll fuction function without extern dfination of dll
Posted
Comments
Richard MacCutchan 9-Mar-11 4:02am    
I do not think that is possible as the information needed to link to the function is not added to the dll file.
Sergey Alexandrovich Kryukov 15-Mar-11 17:13pm    
Possible, possible, it's just ugly formulation of the Question, OP's confused. Please see my Answer.
--SA
Sergey Alexandrovich Kryukov 15-Mar-11 17:15pm    
Possible, possible... It's just ugly formulation of the problem, some OP's confusion.
Please see my answer (I'm sure you know how to do it, too).
--SA
Piccadilly Yum Yum 9-Mar-11 5:04am    
I think its not possible
[no name] 9-Mar-11 6:21am    
Perhaps he does not want to include the .lib and the header in his project and wants to load a DLL at runtime instead. Long ago I loaded plugins to my programs that way. If I remember right, it started out with calling LoadLibrary() and then trying to obtain a function pointers to the functions I wanted to call.

I would suggest to take a look here:
http://msdn.microsoft.com/en-us/library/ms682599(v=vs.85).aspx

1 solution

This is not about if it is possible or not, this is about the concept and perhaps, terminology.
Your formulation of the problem is misleading, that's why people commented your Question like this.

In fact, I think you can do what you want. I don't need external declaration.

Pay attention: external declaration is itself not a definition but only a declaration. It says: this is a function prototype (without the "function body") used to give a syntax for a call, and the definition will be found elsewhere. Yes, you don't really need it. You can use only a function type.

When you already loaded the DLL you need to do GetProcAddress http://msdn.microsoft.com/en-us/library/ms683212(v=vs.85).aspx[^].

So you have the code, why not calling it? You need just some syntax for call. Here you need a function type. Usually, with C++ you use a lib file and *.h file, but you can do without it. A function type is enough.

For example, this is an example of function type from the code sample of "GetProcAddress Function" MSDN help page http://msdn.microsoft.com/en-us/library/ms683212(v=vs.85).aspx[^]:

C#
typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);


Now, look at the full code sample (see reference above). All you need is to declare a pointer to PGNSI (see pGNSI) to obtain the value of this pointer though a type cast from the result of the call to GetProcAddress. When you get non-null result, your are done. Now you can call pGNSI.

I hope it's clear now.

—SA
 
Share this answer
 
v2
Comments
Richard MacCutchan 15-Mar-11 18:13pm    
I don't think this is completely true. If the function in the DLL is not declared with __declspec(dllexport) then it will still not be visible to GetProcAddress().
Sergey Alexandrovich Kryukov 15-Mar-11 18:54pm    
Sorry, what you say is only true for static linking of the DLL (also works with import definition files), not with LoadLibrary. I know for sure.
--SA
Richard MacCutchan 15-Mar-11 19:55pm    
Not true, I just tested it.
Sergey Alexandrovich Kryukov 15-Mar-11 20:16pm    
You could have made mistake, did you think about it. What's not working? I tested dynamic load in this way, it works.

Look, if too people try the functionality, and it work in one case and not another, who is right? The problem is that not working code does not disprove the idea. Show you code if you want, then I can show how to make it working... As simple as that.

--SA
Richard MacCutchan 16-Mar-11 5:01am    
Yes I could have made a mistake but I didn't. I ran my test twice and used Microsoft's Dependency walker to confirm that the function name was not exported without the dllexport.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900