----- Original Message ----- 
From: "Sisyphus" <[EMAIL PROTECTED]>
To: "perl-win32-users" <[email protected]>
Sent: Sunday, June 01, 2008 10:29 PM
Subject: [C/XS] Strange problem with LoadLibrary and VC 7.0

I realise I'm probably only talking to myself here ... it's a sign of 
madness, I believe.

For the record, however, it seems that either Microsoft Visual Studio 7.0 
.NET (Enterprise Architect Edition), or the perl that it builds, is flawed.

I can't fault the compiler in terms of C programs that emulate what I'm 
trying to do in perl - so it's more'n'likely that it's perl that's flawed. 
Probably not worth bothering about, given the small number (one, so far) 
that have been affected by this.

I finally rewrote the test script as:

-------------------------------------------------
use warnings;
use Win32;
use Inline C => Config =>
    BUILD_NOISY => 1;

use Inline C => <<'EOC';

typedef double (CALLBACK* FUNC2)(int);

SV * bar(SV * dll, SV * func, SV * x) {
    HMODULE hinstLib;
    FUNC2 ProcAdd;
    BOOL freelib, fRunTimeLinkSuccess = FALSE;
    double ret = 0;

    hinstLib = LoadLibrary((LPCTSTR)SvPV_nolen(dll));

    if (hinstLib != NULL) {
        ProcAdd = (FUNC2) GetProcAddress(hinstLib, 
(LPCSTR)SvPV_nolen(func));

        if (fRunTimeLinkSuccess = (ProcAdd != NULL)) {
            ret = ProcAdd((int)SvIV(x));
        }

        else printf("GetProcAddress() failed\n");

        freelib = FreeLibrary(hinstLib);
        printf("freelib: %d\nreturn: %f\n", freelib, ret);
        return newSVnv(ret);
    }

    else {
        printf("LoadLibrary() failed\n");
        return newSVnv(ret);
    }
}

EOC

$z = bar("mydll", "d_one_arg", 123);
print $z, "\n";
-------------------------------------------------

With the MinGW compiler that correctly outputs:

freelib: 1
return: 17.571429
17.5714285714286

With VC 7.0, I get:

freelib: 1
return: 17.571429
Use of uninitialized value $z in print at try.pl line 41.

In other words, with VC 7.0, up to and including the following line of code 
in the xsub, everything works fine and as expected:

        printf("freelib: %d\nreturn: %f\n", freelib, ret);

The very next line of code after that is:

        return newSVnv(ret);

and that line obviously either fails to return anything or returns undef. If 
"return newSVnv(ret);" can't function correctly, then I'm just wasting my 
time thinking about it.

Cheers,
Rob 

_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to