c++ - Creating and using a DLL in CPP -


i working on project creating small dll , creating windows application use it.

i can not figure out going on.

i have function in dll called "startpicadorvisual" takes 1 parameter std::string.

in application dependent on dll have following code in auto-generated .h file:

typedef void (__stdcall *f_startpicadorvisual)(string s);  namespace picadorprototype {     f_startpicadorvisual startpicadorvisual;     form1(void) {     //load dll funcs     hinstance hgetprociddll = loadlibrary(l"..\\debug\\picador.dll");      if (!hgetprociddll) {         std::cout << "could not load dynamic library" << std::endl;         throw "bad stuff";     }      startpicadorvisual = (f_startpicadorvisual)getprocaddress(hgetprociddll, "startpicadorvisual");      if (!startpicadorvisual) {         std::cout << "could not locate function" << std::endl;         throw "more bad stuff";     } 

when fails on second step when call getprocaddress.

the functions defined follows in dll:

void __declspec(dllexport) startpicadorvisual(string fixturenamet); picadorresults __declspec(dllexport) getpicadorreading(string fixturename); 

can tell me why isn't working?

getprocaddress fails if name give getprocaddress doesn't match exactly name of function you're calling. exact mean -- characters make function name, function name must match casing, etc.

so either dll exported different name , didn't realize it, or you're not exporting name @ all.

the way can find out names of exported dll functions easily, can use dependency walker program found here: http://www.dependencywalker.com/

also, isn't idea use c++ objects allocate dynamic memory such std::string parameters. if that, dll work applications

  1. are compiled same version of visual c++ dll
  2. use same compiler options when building application , dll
  3. all components (dll , app) must use dll version of c runtime library.

otherwise, code have undefined behavior, more crash, if got far retrieving function pointer correctly.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -