I called from C like this ...
With your Strawberry Perl, any compilation that is done (eg with Inline::C) will be done using gcc-7.1.0.
I don't see any issue with your code and gcc-7.1.0.
And, AFAIK, it doesn't matter whether the dll you want to load was built from C code or C# code or C++ code. Nor should it matter which compiler built it.
There is the problem that "result" is undeclared - which I "fixed" by commenting out "funci(&result)", as that else block will never be entered in my case, anyway.
The program then compiled and ran cleanly when built with gcc, outputting "DLL not found" (as expected).
If that program works fine for you, then it should be fine with Strawberry Perl and Inline::C ... unless, of course, DLLExportTest.dll wants to load a file (eg another dll) that is not locatable in the Srawberry Perl environment.
This Inline::C script runs fine for me on Strawberry Perl 5.26.0 and, after compilation, outputs "initdll returned: 0".
use strict;
use warnings;
use Inline C => Config =>
BUILD_NOISY => 1;
use Inline C => <<'EOC';
typedef int (__stdcall *f_funci)();
int initdll()
{
double a = 1;
double b = 2;
HINSTANCE hInst =
LoadLibrary("C:\\dev\\teste\\DLLExportTest.dll");
if( hInst != NULL )
{
f_funci funci = (f_funci)GetProcAddress(hInst, "Add");
if (!funci) {
printf( "could not locate the function\n" );
return EXIT_FAILURE;
} else {
/* funci(&result); */
}
FreeLibrary( hInst ); // temporary
return 1;
}
else
{
return 0;
}
}
EOC
print "initdll returned: ", initdll(), "\n";
Cheers,
Rob
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.