guilhermecgs
guilhermecgs

Reputation: 3041

DLL function name different from exported

I´m using a program developed by someone else using c++ and matlab. I have the source code of both, but I don't know what is going on...

Matlab calls a dll generated from c++ using something like this:

myCustomCppFunction('param1', 'param2)

I was expecting to see myCustomCppFunction in the dll exports, but I could not find it.

When I run dumpbin command, I receive something like this:

dumpbin /exports c:/myCustomCpp.dll
ordinal hint RVA      name
1    0 00001010 myCustomCppFunctionWithADifferentName

So,

myCustomCppFunctionWithADifferentName != myCustomCppFunction

The DLL is exporting a function name that is different than the function name that my matlab is calling. And I'm not talking about mangled names, both names are 100% different, like 'apple' and 'banana'. :-)

Somehow, everything works fine! but how?!?

In Matlab, I also ran which command that confirms to me that the function called is from the DLL I´m investigating....

>> which myCustomCppFunctionWithADifferentName
>> c:/myCustomCpp.dll

any clues?

Upvotes: 0

Views: 308

Answers (1)

chappjc
chappjc

Reputation: 30579

Aside from your tag, I'm not sure your dealing with a MEX file.

The name of a MEX file (a DLL) is not related to the name of the exported function. The exported function in a MEX file is:

mexFunction

In Windows, there is still a DLLMain, but MATLAB looks for mexFunction.

So this is what happens:

>> myMEXFunction()  % looks for myMEXFunction.mexw64 (or whatever extension)

If myMEXFunction.mexw64 has mexFunction exported, you are in business.

Note that mexFunction is declared in mex.h as extern "C" (if you are compiling a .cpp), you just define it in your source. So it will always be undecorated.

However, your myCustomCpp.dll does not export mexFunction, so perhaps you are not talking about a MEX file? Also, what makes me more uncertain if you are talking about a MEX file is the strange result you get with which. Is your MATLAB source (myCustomCppFunction) actually using loadlibrary or calllib to operate with the DLL? If myCustomCppFunction() loaded a non-MEX DLL in this fashion, then what you are showing makes sense.

Upvotes: 1

Related Questions