http://www.perlmonks.org?node_id=663147


in reply to WIN32-API Purgetory

Maybe it's a problem with Win32::API? You might try using Inline::C. The following code probably won't work (I don't have the library, and haven't tested the code anyway), but it may give you some ideas on how to approach this problem:
use Inline::C; $transbar = "\0"x66; $bardata = "3070202120200000000127203643012"; $rc =0; $track = substr($bardata,0,20) . "\0"; $route = substr($bardata,20,11) . "\0"; $rc = barcode($track,$route,$transbar); print "$transbar \n"; __C__ #include <windows.h> // setup our data structures typedef int (__cdecl *USPS4CB)(char *,char *,char *); HINSTANCE hDLL; USPS4CB lpfnUSPS4CB; //load the DLL hDLL = LoadLibrary("USPS4CB"); if (hDLL != NULL) { //get a pointer to the function we'll call lpfnUSPS4CB = (USPS4CB)GetProcAddress(hDLL, + "USPS4CB"); if (!lpfnUSPS4CB) // problem loading the function { FreeLibrary(hDLL); // here we would kill our perl process or something, cause // loading the library failed // I don't do too much of this, so I'm not quite sure // how to properly fail fatally } } // function for perl to call int barcode(char *track, char *route, char *transbar) { // call the function return lpfnUSPS4CB(track, route, transbar); }
Let me stress that I haven't tested that code, and it may not work. It's mainly just an idea on where I'd go if the Win32::API module isn't working. For example, if you don't have access to Inline::C, then this approach doesn't even have a chance of working.