🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #11319

Re: Loaded DLL function won't work

#11319
From: Ed Mulroy [TeamB]
Date: Wed, 18 Feb 2004 22:58
113 lines
3786 bytes
I took the types I used from his messages lines that are reproduced below.

> ...  If I try to compile with this:
> (Proc) (szRunTypes, (char *)&rntyptable);
> which is how it ought to be ...

You are correct that it is
    int __stdcall(*
and not
    int (* __stdcall

Good catch!

You are not correct in your objections to the cast to type FARPROC.  It is a
cast on an lvalue, not a declaration.  As you can see below it works ok.

----------------------------------
C:\DOCUME~1\ADMINI~1\MYDOCU~1\Lookat\q006
>type testit.cpp
  #include <windows.h>
  #include <cstdio>

  using std::printf;

  int main()
    {
    HMODULE Lib = LoadLibrary("NYSiteP.dll");
    int __stdcall (*Proc)(char *, char *);

    if (Lib != NULL)
        {
        (FARPROC) Proc = GetProcAddress(Lib, "SITE");

        if (Proc != NULL)
            {
            printf("should be 8: %d\n", Proc("123", "45678"));
            printf("should be 4: %d\n", Proc(NULL, "1234"));
            }

        FreeLibrary(Lib);
        }

    return 0;
    }


C:\DOCUME~1\ADMINI~1\MYDOCU~1\Lookat\q006
>type nysitep.cpp
    #include <windows.h>

    BOOL WINAPI DllEntryPoint(HINSTANCE, DWORD, LPVOID)
      {
      return TRUE;
      }

    extern "C"
    int __declspec(dllexport) __stdcall SITE(char *Test, char *data)
      {
      int result = (Test) ? lstrlen(Test) : 0;

      if (data)
        {
        result += lstrlen(data);
        }

      return result;
      }

C:\DOCUME~1\ADMINI~1\MYDOCU~1\Lookat\q006
>bcc32 -WCR testit
Borland C++ 5.6.4 for Win32 Copyright (c) 1993, 2002 Borland
TESTIT.CPP:
Turbo Incremental Link 5.64 Copyright (c) 1997-2002 Borland

C:\DOCUME~1\ADMINI~1\MYDOCU~1\Lookat\q006
>bcc32 -WDR nysitep
Borland C++ 5.6.4 for Win32 Copyright (c) 1993, 2002 Borland
NYSITEP.CPP:
Turbo Incremental Link 5.64 Copyright (c) 1997-2002 Borland


C:\DOCUME~1\ADMINI~1\MYDOCU~1\Lookat\q006
>testit
should be 8: 8
should be 4: 4

C:\DOCUME~1\ADMINI~1\MYDOCU~1\Lookat\q006
>

----------------------------------

.  Ed

> Remy Lebeau wrote in message
> news:4033dc64$3@newsgroups.borland.com...
>
>
> >   int (*__stdcall Proc)(szRunTypes, char*&);
>
> Shouldn't be be more like this instead?
>
>     int __stdcall (*Proc)(char*, char*);
>
> From Peter's description, szRunTypes is a variable, not a data type.  And
> there is no reference used for the second parameter.
>
> >       Proc = (int(*__stdcall)(szRunTypes,char*&))
> >           GetProcAddress(Lib, "SITE");
>
> You declared the Proc variable to be FARPROC.  Wouldn't that cast fail
then?
> Also, since it is a FARPROC, wouldn't you need to past the pointer again
> when actually calling the exported function?
Technical Details
Message-ID: <4033ee2f$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4033d5c9$1@newsgroups.borland.com> <4033d84d@newsgroups.borland.com> <4033dc64$3@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,5a8f68731742a0dc
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2004-02-18 15:10:00 PST
From: "Ed Mulroy [TeamB]" <dont_email_me@bitbuc.ket>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <4033d5c9$1@newsgroups.borland.com> <4033d84d@newsgroups.borland.com> <4033dc64$3@newsgroups.borland.com>
Subject: Re: Loaded DLL function won't work
Date: Wed, 18 Feb 2004 17:58:34 -0500
Lines: 115
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 24.74.175.102
Message-ID: <4033ee2f$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1077145135 24.74.175.102 (18 Feb 2004 14:58:55 -0800)
X-Authenticated-User: edmulroy
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail