Reputation: 167
Good afternoon, all.
I was playing around today with Excel & VBA loading some DLLs and seeing what kind of trouble I could get into.
I made my own, very simple DLL to try it out. I can't for the life of me figure out why, but I keep getting the "Specified DLL function not found" message when I try to run.
Here's what I have in my workbook...
Private Declare Sub MouseClick Lib "\location\of\myDLL" Alias "_MouseClick" ()
'I have also tried...
'Private Declare Sub MouseClick Lib "\location\of\myDLL" ()
Sub Test()
MouseClick
End Sub
Here's my simple function declaration in the DLL...
extern "C"
{
void MouseClick();
...
}
I thought that maybe the name of my function was being mangled when compiled, so I used 'nm' to check...
$ nm myDLL.dll | grep MouseClick
6df81254 T _MouseClick
$ nm -C myDLL.dll | grep MouseClick
6df81254 T MouseClick
I don't understand... I've used both of those to try to get it to work. Also, I disassembled a function that calls the MouseClick function using gdb...
$ gdb myDll.dll
(gdb) disass testFunction
Dump of assembler code for function testFunction:
0x6df81327 <+0>: push %ebp
0x6df81328 <+1>: mov %esp,%ebp
...
0x6df81361 <+58>: call 0x6df81a44 <SetCursorPos@8>
0x6df81366 <+63>: sub $0x8,%esp
-> 0x6df81369 <+66>: call 0x6df81254 <MouseClick>
0x6df8136e <+71>: jmp 0x6df8138a <testFunction+99>
...
0x6df8138a <+99>: leave
0x6df8138b <+100>: ret
End of assembler dump.
Here, too the function is referred to as "MouseClick".
I may be going about this all the wrong way, but I don't understand why gdb and nm are both showing a "clean" function name, but Excel won't work with either of the ones I assumed it would be. I did get the dll to work with my VBA sub for a time, but I changed the document and now it's not working.
Would someone that has done this before be kind enough to point me in the right direction about all this? What should I name the function in Excel? Why is nm showing a function name that isn't mangled? Am I even going about this the right way?
Thanks to all in advance!
Upvotes: 0
Views: 1092
Reputation: 28737
Somebody went through all this already and updated his question to include the solution:
Compile a DLL in C/C++, then call it from another program
The answer is specific for gcc, which is what you seem to use.
Upvotes: 1