Author Topic: The PB-methode: @pointer[n] inside a C++-DLL????  (Read 2702 times)

0 Members and 1 Guest are viewing this topic.

Offline Heinz Grandjean

  • Newbie
  • *
  • Posts: 22
The PB-methode: @pointer[n] inside a C++-DLL????
« 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
Code: [Select]
'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:
Code: [Select]
// 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

Offline Heinz Grandjean

  • Newbie
  • *
  • Posts: 22
Re: The PB-methode: @pointer[n] inside a C++-DLL????
« Reply #1 on: December 25, 2014, 07:18:10 PM »
Problem solved.
"MoveMemory" does the job!

Thanks,
Heinz Grandjean

Offline Frederick J. Harris

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 938
    • Frederick J. Harris
Re: The PB-methode: @pointer[n] inside a C++-DLL????
« Reply #2 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.