Link to home
Start Free TrialLog in
Avatar of chris rrr
chris rrrFlag for United States of America

asked on

dll calling functions from my sdk

given:
main app   = main application
plugin        = dll that main app calls (this is built using the main app sdk)
myDll         = my dll that my plugin calls

I am writing a plugin which is a dll. This is called to from a main app.
To build my plugin I must use the sdk that the developers for the main app have given me.
Now, My plugin has its own dlls that it links to (myDll), and It works perfect....as long as I don't use any of the functions from the sdk in myDll's functions.

My main question would be. "How can I use functions from the sdk in myDll".

When building myDll I am including all of the headers etc. All of the defines and typedefs work. I can even use the functions in a define (as long as I never call my define);

I have been researching for a while and it seems like I should be able to use a .def file. Well that didn't work. But I don't know if I am linking it wrong or if it just isn't working. (never done this before).

Please help if it is possible...thanks

Oh...here is my error I get when I place an sdk function in any of myDll's functions.

==================  I get this error  ==================

Linking...

   Creating library Release/Dll_01.lib and object Release/Dll_01.exp

Dll_01.obj : error LNK2001: unresolved external symbol _fxMessageSend

D:\AppWSDK\plugins\MyDlls\Dll_01.dll : fatal error LNK1120: 1 unresolved externals

Error executing link.exe.

================================================

 


Avatar of Dexstar
Dexstar

cafechris:

> Dll_01.obj : error LNK2001: unresolved external symbol _fxMessageSend

> D:\AppWSDK\plugins\MyDlls\Dll_01.dll : fatal error LNK1120: 1 unresolved externals

This linker error means that the linker can't find the module with that function in it, and it needs it in order to complete the compilation process.  This function is probably in a .LIB file that was included with the SDK.  Add that to your project and it should compile just fine.

Hope That Helps,
Dex*
Avatar of chris rrr

ASKER

There are no .lib files in the sdk. (only some dll's called ie: vectorlib.dll etc.....I opened them in dependency walker and they only have one function that is exported ie: InitFunction)

I can try to contact the developers and see if I can get a .lib file, but if it is some sort of security issue they won't share it.
I don't know anything about lib files and such... Does anybody have any good articles on this . I would love to learn more.

Is it possible to make a .lib file from all of the header files. (for some reason I thought I have seen this somewhere)
ASKER CERTIFIED SOLUTION
Avatar of Dexstar
Dexstar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Actually there are no lib files or dll files in the sdk at all.
When I went back to look all of the files that I found before were in the main_apps folder.

I opened every file with dependency walker and there were none that export fxMessageSend.

I do have close ties to the developers and emailed them asking for a lib file.
I guess we will have to wait and see what there response is.

While we wait......
I will give an extra 25pts (I am raising from 250pts to 275pts so I can split it) to the best  definition/link/whatever  of how  libs work and what they are.

I have yet to find a good definition.

Thanks
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Basically, a .LIB file is a "list of things to do" for the linker in order for it to link a .DLL file STATICALLY into your executable. What is statical linking? In this context, it's being able to simply call "MessageBox()" instead of having to type:

HANDLE h;
function pointer type [(int (*)(HANDLE, char *, char *, int))] pMessageBox;
if ((h = LoadLibrary("USER32.DLL")) == NULL) fail();
if ((pMessageBox = GetProcAddress(h, "MessageBox")) == NULL) fail();
pMessageBox(a, b, c, d);

As you have no doubt already seen, the "import table" is put directly inside your application, resulting in both that a simple "MessageBox()" works as well as the ugly code above, and that a program such as that DependancyWalker can easily tell which executable calls which function from which DLL.
bsnh99
Thanks, that link really helped with understanding the lib. and some of my options.

aib_42
Thanks, for your answer above. Basically you said what the link I just looked at said.

I still havn't heard back from the developers yet. So I can't get the lib.
I already knew about the LoadLibrary, and GetProcAddress. I am currently using them in my plugin
Because I need to load and then free mydll manually.

Tell me if this is true:
If I would link from my plugin to myDll with a .lib, I wouldn't be able to free the dll.--correct?
Hence the term static. If I am right, I have learned alot already... ;?)

Thanks you guys, I still have to wait for the .lib it looks like. Because myDll does have to call functions from the sdk. And I don't want to go through the sdk and make all of the functions exportable.
> Tell me if this is true:
> If I would link from my plugin to myDll with a .lib, I wouldn't be able to free the dll.--correct?
> Hence the term static. If I am right, I have learned alot already... ;?)

True, unless there's some fancy force-unload hack I do not know about :). If you examine an application with a debugger, you will see that Windows loads the DLL's just before the main thread starts and unloads them just after the main thread quits.

Heh, I'm sorry about repeating the thread, but this very thing had puzzled me for quite a time in the past, and I wanted to clear it out for you as soon as I could!

Oh, by the way, is there any chance you are mixing C code with C++ code? That creates a lot of problems with linkage.

Also, if you're still interested in building your own .lib from the DLL, check out:

https://www.experts-exchange.com/questions/20853012/Creating-a-lib-file-from-a-DLL-ntdll-dll-Visual-C-Win2K-XP.html

(Though it would be easier to get the .lib file from the developers.)
>Oh, by the way, is there any chance you are mixing C code with C++ code? That creates a lot of problems with linkage.

The sdk is written in 'C'. However I do see some places were they say something like:
#if defined(__cplusplus)
      #define __EXPORTVAR(t)      extern "C" t
#else
      #define __EXPORTVAR(t)      t
#endif

I am very sure it is written in c because the people I know who use it don't know c++.

>Also, if you're still interested in building your own .lib from the DLL, check out:

thanks, but there are no dll's in the sdk...I was wrong, they are the apps dll's.

>Heh, I'm sorry about repeating the thread, but this very thing had puzzled me for quite a time in the past,
Actually you showed me some syntax something that I had never seen before
ie: function pointer type [(int (*)(HANDLE, char *, char *, int))] pMessageBox;
I don't even know if I understand it...what does [] mean. I've only seen this in arrays[].
That was my way of distinguishing between the explanation ("function pointer type") and the actual code ("int ...")

The proper syntax should be something like:
(int (*)(HANDLE, char *, char *, int)) pMessageBox;
as you say you already know.
Ok,
I talked to the developers and they pointed me to a #define header file that was neccessary to compile the functions.

Almost Great....
It compiles no problem,,,,

But now my dll wont load into my plugin.

is there a way to LoadLibrary( exeFile) and get the function from the Application exe. ( I guess it would have to be
extern  __declspec(dllexport) )...that would mean changing the header file. I think that may mess up other users and my plugin.

Or is there an easy way around this and maybe pass the function pointer to my dll. I will see if I can figure it out.

Any Ideas on this....

Chris
********      NOTE: NO GOOD SOLUTION WAS FOUND     ******** hack ****
ok,
got it to work by creatng a function for my plugin that would take a flag, and one of each variable type pointers. then I would pass the address to myDll. the dll would work its magic and pass back the flag and any arrays that would go with it.

Then in my plug I would have a switch statement that would use the flag as the case. Each case would use what it needed out of the arrays.

This is crappy because of all of the setup neccessary. It is not a good solution. Unfortunately I had to pick a solution for the question. I chose the first person to respond with good answers. Then I split the points up between those who helped. (and also gave the 25pts to the best .lib answer)

Thanks everyone for the help.

Chris Reid