c++ - Exporting Symbol to DLL (via Module Definition File) Worked, But I Don't Know Why -


i performing experiments learn precise rules of module definition files, , came across behavior can't explain. here's set-up:

nonmemberfunctions.h

#pragma once  extern "c" void __stdcall nonmembertestfunction1(); void __stdcall nonmembertestfunction2(void); extern "c" void nonmembertestfunction3(void); 

nonmemberfunctions.cpp

#include <comutil.h> #include "nonmemberfunctions.h"  extern "c" void __stdcall nonmembertestfunction1() {     messagebox(null, l"non-member test function1", l"hi", mb_ok); }  void __stdcall nonmembertestfunction2() {     messagebox(null, l"non-member test function2", l"hi", mb_ok); }  extern "c" void nonmembertestfunction3() {     messagebox(null, l"non-member test function3", l"hi", mb_ok); } 

exports.def

library "test1" exports     nonmembertestfunction1     nonmembertestfunction2     nonmembertestfunction3 

excel vba module

option explicit  public declare sub nonmembertestfunction1 lib "c:\foo\test1.dll" () public declare sub nonmembertestfunction2 lib "c:\foo\test1.dll" () public declare sub nonmembertestfunction3 lib "c:\foo\test1.dll" ()  sub test1()     call nonmembertestfunction1     call nonmembertestfunction2     call nonmembertestfunction3     end  ' release dll can recompile end sub 

the surprising thing dll calls worked. wasn't expecting that. way see world, there 3 hurdles:

  1. exportation of symbol
  2. the calling convention
  3. name mangling

plopping 3 symbols module definition file enough take care of #1.

for hurdle 2, i'm surprised call #3 worked because c calling convention cdecl, vba calling convention stdcall, , 2 (i thought) incompatible.

for hurdle 3, i'm surprised call #2 worked because function #2 should've had name mangled. think reason name mangling distinguish function signatures differ argument, true non-member functions member functions. how did work? used dependency walker @ exported symbols in dll, , sure enough, 3 functions had names intact:

??0ctest1@@qae@xz ??1ctest1@@qae@xz ??4ctest1@@qaeaav0@abv0@@z ?ctest1public1@ctest1@@qaexxz nonmembertestfunction1 nonmembertestfunction2 nonmembertestfunction3 

i understand why nonmembertestfunctions 1 , 3 not name mangled, why isn't nonmembertestfunction2 not name mangled? should have c++ linkage.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -