Announcement

Collapse
No announcement yet.

Help needed translating a C statement to a DECLARE

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help needed translating a C statement to a DECLARE

    Code:
    extern "C" __declspec(dllexport) int __stdcall FunctionName(void* p)
    p = DLL address
    Last edited by Mike Doty; 6 Sep 2010, 02:34 PM.
    CMD shortcut to open any location:
    %windir%\system32\cmd.exe /k " cd\ & x: & cd x:\xxxx
    Change to run as administrator
    How long is an idea? Write it down.

  • #2
    Code:
    Declare FunctionName Lib "NameOfDll" Alias "FunctionName" (pVoid As Dword Ptr) As Long
    
    or
    
    Declare FunctionName Lib "NameOfDll" Alias "FunctionName" (pVoid As Dword) As Long
    depending on how you want to use the void pointer which in C has to be cast to some ledgitimate variable type befor use.

    The extern "C" thing just tells a C++ compiler not to mangle the function name so that it will show up correctly in the export list. __declspec dllexport is a Microsoft specific procedure attribute used similiarly to PowerBASIC's export keywork. An int in C/C++ is a signed 32 bit number, just like a C long or PB Long.
    Last edited by Fred Harris; 6 Sep 2010, 05:24 PM.
    Fred
    "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"

    Comment


    • #3
      There may be some problems depending on if CDECL or STDCALL is used (or if default is used) but Fred's code will DEFINITELY get you closer.

      Fred, Nice catch with the "ALIAS" part though
      Engineer's Motto: If it aint broke take it apart and fix it

      "If at 1st you don't succeed... call it version 1.0"

      "Half of Programming is coding"....."The other 90% is DEBUGGING"

      "Document my code????" .... "WHYYY??? do you think they call it CODE? "

      Comment


      • #4
        pVoid As Dword
        Better declare it as BYVAL DWORD.
        Forum: http://www.jose.it-berater.org/smfforum/index.php

        Comment


        • #5
          Better declare it as BYVAL DWORD.
          Oops! Forgot about that part!
          Fred
          "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"

          Comment


          • #6
            ?p = DLL address

            ???

            A DLL does not have an 'address.'

            A c 'void*' might be best translated to PB as "AS ANY" , but in PB-syntax that's only allowed in the DECLARE, not in the procedure header.

            So just ask yourself what you would put in the procedure header if you found a PB DECLARE with an 'AS ANY' parameter.
            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              Thank you!
              CMD shortcut to open any location:
              %windir%\system32\cmd.exe /k " cd\ & x: & cd x:\xxxx
              Change to run as administrator
              How long is an idea? Write it down.

              Comment


              • #8
                A c 'void*' might be best translated to PB as "AS ANY"
                It depends on usage. In the case of this function, where you have to pass a pointer by value, declaring it AS ANY instead of BYVAL AS DWORD will force you to always having to use the BYVAL override.
                Forum: http://www.jose.it-berater.org/smfforum/index.php

                Comment


                • #9
                  "conceptually" a c 'void *' is a PB 'AS ANY'

                  Or .... in what you sometimes see in some of the WinAPI documention, "an unsigned integer which has meaning only to the caller or callee" ... which of course can be expanded to "four bytes which have meaning only to the caller or callee."

                  How one chooses to express this concept in a PB DECLARE statement or when creating a parameter in a PB procedure header is one hundred percent a programmer option, as long as the integrity of the concept is maintained.

                  Yes, I know. It's so much easier when there is one and only one right answer you can look up in a table somewhere. Well.... too bad, that's not the case; deal with it.


                  MCM
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment

                  Working...
                  X