Send an array to a dll

BlitzMax Forums/BlitzMax Programming/Send an array to a dll

Hi,
I'm trying to send an array to a dll, but I can't send it. My application crashes.

the function in my dll is (written in C):
void ModifieTableau (int ptr[10])
{
   int i;
   for (i=0; i<10; i++)
   {
      ptr[i] = 15;
   }
}


the code in BlitzMax is:
Const DllName:String = "dllTest.dll"
Local DllHandle = LoadLibraryA(DllName)

If DLLhandle = 0 Then
   Notify "Unable to initialize dllTest.dll"
   End
EndIf

Global HelloWorld()"Win32" = GetProcAddress(DllHandle,"HelloWorld")
Global EnvoieValeur:Int(a:Int)"Win32" = GetProcAddress(DllHandle,"EnvoieValeur")
Global ModifieTableau(tab:Int Ptr)"Win32" = GetProcAddress(DllHandle,"ModifieTableau")

Local tableau:Int[10]
Local tab_ptr:Int Ptr
tab_ptr = Varptr tableau[0]

For i = 0 To 9
   tableau[i] = 5
Next

For i = 0 To 9
   Print(tableau[i])
Next

ModifieTableau(tab_ptr)     ' Application cashes here "Unhandled exception: Attempt to call uninitialize function pointer"

For i = 0 To 9
   Print(tableau[i])
Next


Could anyone help me ?

Copy everything from the array to a TBank and send that.

Array is no plain array like in C where it is a continous memory block so you can't send it to C apps.

thanks for your reply :)

After a few tries, here are my modifications:
void ModifieTableau (int* ptr)
{
   int i;
   for (i=0; i<10; i++)
   {
      ptr[i] = 15;
   }
} 

for the dll

Const DllName:String = "dllTest.dll"
Local DllHandle = LoadLibraryA(DllName)

If DLLhandle = 0 Then
	Notify "Unable to initialize dllTest.dll"
	End
EndIf


Global EnvoieValeur:Int(a:Int)"Win32" = GetProcAddress(DllHandle,"EnvoieValeur")
Global ModifieTableau(tab:Byte Ptr)"Win32" = GetProcAddress(DllHandle,"ModifieTableau")

Local i:Int
Local bank_ptr:Byte Ptr

Local MaBank:Tbank = CreateBank(10 * SizeOf(i))

bank_ptr = BankBuf(MaBank)

For i = 0 To 9
   PokeInt(MaBank, i*SizeOf(i), 10)
Next

For i = 0 To 9
   Print(PeekInt(MaBank, i*SizeOf(i)))
Next

ModifieTableau(bank_ptr)

For i = 0 To 9
   Print(PeekInt(MaBank, i*SizeOf(i)))
Next

in BlitzMax.

The different types between BlitzMax and C is quite confusing for me :/

Thanks again :)

wheres EnvoieValeur at least meet us half way!!

EnvoieValeur is a very simple function. I have no problem with it.

My problem was about sending an array to a dll.
It works with a bank, with the previous code, so I'll do like that.

Thanks :)

yeah but without it no one can run code, see where it fails, fix it, and help you out...

Ignore the bank comment and concentrate on the error "Attempt to call uninitialized function pointer".

I'd guess this means GetProcAddress(DllHandle,"ModifieTableau") is failing and returning null.

I would double check your spelling and make sure you are using c and not c++ (.c not .cpp file) for your dll else you will need to declare your function as extern "C" to stop it's name being mangled by the c++ compiler.