Powerbasic Museum 2020-B

IT-Consultant: Frederick J. Harris => PowerBASIC Programmer's Survival Guide To C And C++ => Topic started by: Heinz Grandjean on December 23, 2014, 09:55:43 PM

Title: The PB-methode: @pointer[n] inside a C++-DLL????
Post by: Heinz Grandjean on December 23, 2014, 09:55:43 PM
Hello community!
Sending arrays of a PB-type to a function inside a PB-DLL I normally send the pointer of array(0).
Inside the DLL I can access all the elements by using @ptr[n]= ...
I'm looking for a method to use the same technique while linking to C++-DLL.
The linking in itself is ok. It is not the topic of my question!
Let me show some code-snippets:
PB-Side

'Declaration:
TYPE myType
      var1 AS LONG
      Var2 AS LONG
END TYPE

'Later:
DIM myTest(255) AS myType

'Declares:
DECLARE FUNCTION myC_Function CDECL ALIAS "myC_Function" _
         ( _
         BYVAL myTest PTR _
         )


'Later:
CALL DWORD myC_address USING myC_Function _
      ( _
      VARPTR(myTest(0)) _
      )       


C+++ Side:

// Declares:
struct mytest
{
    unsigned long Var1;
unsigned long Var2;
};
mytest mytest_arr[255];

//Export-declare:
#define C_EXPORT extern "C" __declspec(dllexport)
C_EXPORT long C_mytest (
                   mytest*
   );

//Function:
long C_mytest
(
mytest *pmytest_arr
)
{
   mytest_arr[0] = *pmytest_arr; //as far as I have tested: this is OK!?

   /*The question now, how to fill mytest_arr[1 to 254] according to the
    PB-practice "mytest_arr[1] = @pmytest_arr[1]" etc.?
   */
};


Maybe there is an idea?
Merry Christmas to you all!
Frohe Weihnachten!

Heinz Grandjean
Title: Re: The PB-methode: @pointer[n] inside a C++-DLL????
Post by: Heinz Grandjean on December 25, 2014, 07:18:10 PM
Problem solved.
"MoveMemory" does the job!

Thanks,
Heinz Grandjean
Title: Re: The PB-methode: @pointer[n] inside a C++-DLL????
Post by: Frederick J. Harris on January 05, 2015, 07:36:18 PM
I'm really sorry I missed your post Heinz.  I didn't see it until about 12/30.  I usually check every other day or so, but the holidays threw me off. 

Glad you found a solution though.  MoveMemory(), along with  a lot of the msvcrt functions, are useful.