Solved

dll calling functions from my sdk

Posted on 2004-09-11
13
1,842 Views
Last Modified: 2013-12-14
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.

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

 


0
Comment
Question by:cafechris
  • 6
  • 4
  • 2
  • +1
13 Comments
 
LVL 19

Expert Comment

by:Dexstar
ID: 12036051
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*
0
 
LVL 1

Author Comment

by:cafechris
ID: 12036225
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)
0
 
LVL 19

Accepted Solution

by:
Dexstar earned 125 total points
ID: 12036276
cafechris:

> 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)

Without a .lib, it's tricky.  I can't believe they didn't give you one.  

You've opened all of the DLLs?  Open each one in the SDK and in the main program.  There should be one that exports fxMessageSend.  When you find it, you can use LoadLibrary to get a pointer to the function, do it that way.  I'll show you how once you find the DLL that has it.

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

No, that's not possible.  Usually, you have a header file (or set of header files) and a .lib file.  Together, you should be able to use the code they provided.

-D*
0
 
LVL 7

Assisted Solution

by:aib_42
aib_42 earned 125 total points
ID: 12036300
What is fxMessageSend? Normally, the application should make calls to your DLL, not the other way around. If you need to make a call to a function the application uses, however; if a) the function is in the application executable, you need to be supplied the source code, and if b) the function is in a DLL that the application uses, you either need the source code or some linkage to the DLL. You can link it dynamically, ie use LoadLibrary() and GetProcAddress() functions and then call the function, or generate a .lib and link it statically. (You can generate .lib files from .dll's.)
0
 
LVL 1

Author Comment

by:cafechris
ID: 12036450
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
0
 
LVL 1

Assisted Solution

by:bsnh99
bsnh99 earned 25 total points
ID: 12036738
For more detail on what aib_42 suggests, see:

    http://www.flipcode.com/tutorials/tut_dll01.shtml

Scroll down to dllrun02.cpp. You may be able to get around the missing .LIB.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 7

Expert Comment

by:aib_42
ID: 12036880
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.
0
 
LVL 1

Author Comment

by:cafechris
ID: 12036956
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.
0
 
LVL 7

Expert Comment

by:aib_42
ID: 12037485
> 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:

http://www.experts-exchange.com/Programming/Programming_Platforms/Win_Prog/Q_20853012.html

(Though it would be easier to get the .lib file from the developers.)
0
 
LVL 1

Author Comment

by:cafechris
ID: 12038776
>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[].
0
 
LVL 7

Expert Comment

by:aib_42
ID: 12041008
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.
0
 
LVL 1

Author Comment

by:cafechris
ID: 12061778
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
0
 
LVL 1

Author Comment

by:cafechris
ID: 12261481
********      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
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
I made this because I wanted to get e-mail with a attached csv file so I'd would be able to import user input into a MS Excel template, but I also wanted to register/save all inputs from each day in a file on the server. 1st - It creates a temp C…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now