lire résultat DLL tableau de float

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
PBW32
Messages : 19
Inscription : mer. 15/sept./2010 21:37

lire résultat DLL tableau de float

Message par PBW32 »

Bonjour a tous ! C'est mon premier post ici !

j'ai une DLL (écrite en C++) toute simple, qui prend un tableau (array) de 3 floats en argument et qui place la somme des 2 premier éléments dans le 3éme élément.

le code C ++:

Code : Tout sélectionner

#include <stdio.h>

extern "C"
{
   __declspec(dllexport) void MyFunction(float*);
}

void MyFunction(float* myData)
{
   myData[2] = myData[0] + myData[1];
}
Cela fonctionne parfaitement quand j'y accéde avec un script Angelscript (language de scripting proche du C).
Mais en PB, je n'y arrive pas, voila mon code PB d'accés a la DLL :

Code : Tout sélectionner

Dim tableau.f(3)
tableau(0)=1
tableau(1)=2
tableau(2)=666666

;Debug tableau(2)

PrototypeC.f MyFunction(tableau.f) ; PrototypeC ou Prototype ? dll type win ou C ?


If OpenLibrary(0, "MyDLL.dll") 
MyFunction.MyFunction= GetFunction(0,"MyFunction") 
If MyFunction = 0
   Debug "Fonction non trouvée dans la DLL ..."
   End
EndIf
Else
  Debug "DLL non trouvée..."
  End
EndIf 

Debug MyFunction.MyFunction ;renvoit un handle ? -->268439769

je voudrais que les résultats retournés par la DLL soient insérés dans le tableau PB. Comment faire ?

Autre question, a quoi ressemblerait de code de la DLL écrit en PB ? Merci ...
PBW32
Messages : 19
Inscription : mer. 15/sept./2010 21:37

Re: lire résultat DLL tableau de float

Message par PBW32 »

Si ça peut aider, voici le code AngelScript d'appel de la DLL :

Code : Tout sélectionner

//This script shows how to call a function in a user-made DLL.
//For this example we have compiled a minimal DLL with one single
//exposed function called 'MyFunction'.

//The user DLL function receives a float array handle as parameter.
//This is the base of an internal array provided by the Script object.

//This particular user function adds the first two values in the array
//and places the result in the third element.

int DLLHandle = 0;
void Main()
{
   if (iInitializing())
   {
      //load the test DLL module to make its functions available to this script
      DLLHandle = iDLLLoad(".\\3DRad_res\\objects\\Script\\MyDLL.dll");
   }
   else if (iDeinitializing())
   {
      //free memory resources used by the DLL module
      if (DLLHandle != 0) iDLLUnload(DLLHandle);
   }
   else
   {
      if (DLLHandle != 0)
      {
         //set the first and second values in the float array to 3 and 4 respectively
         iDLLArraySet(0,3);
         iDLLArraySet(1,4);
         //set the third value to zero
         iDLLArraySet(2,0);
         //call the user-defined function in the test DLL module
         iDLLCall(DLLHandle,"MyFunction",0);
         //read the third value in the array (result) and send it to the ValuePrint object for rendering
         OUT_0 = iDLLArrayGet(2);
      }
   }
}
Répondre