C Structures Word Dword and bytes?!

BlitzMax Forums/BlitzMax Programming/C Structures Word Dword and bytes?!

Haramanai(Posted 2010) [#1]
Hi.
I am trying to make a wrap of a dll for BlitzMax.

My problem is that some functions returns C structures that contains DWORD and WORD , and my only clue of how those structures look like is a python wrapper. that looks like this.
class Help(Structure):
     _fields_ = [("Data1", DWORD),
             ("Data2", WORD),
             ("Data3", WORD),
             ("Data4", BYTE * 8)]


So I created a Type like this :
Type Help
	Field Data1:Int			'DWORD
	Field Data2:Short		'WORD
	Field Data3:Short		'WORD
	Field Data4:Byte[8]  	'BYTE * 8 
	
End Type


I readed that DWORD and WORD does not have standard bits. For example on a 32bit system WORD is 32bit and on 64bit system it's 64... I am not sure... I am working on a 64bit system.

So when I ran the function

Global dll = LoadLibraryA("dll")
Global Function please:Help(me:int)"win32" = GetProcAddress(dll , "please")
please(1)


I get the message "EXCEPTION ACCESS VIOLETION"

Can someone point me to the right direction?

Sorry for my English...

Thanks.


Brucey(Posted 2010) [#2]
You cannot return a BlitzMax type from an external function like that. It won't work. BlitzMax types have (at least) an extra 4 bytes as part of their internal structure, and so what you would be returning would be the wrong size anyway.

There are ways to do it in BlitzMax though - see the FreeType module for some ideas on mixing Types with C struct data.


Haramanai(Posted 2010) [#3]
Thanks.
I will do that.


Azathoth(Posted 2010) [#4]
Arrays in structs are different in C, the elements are part of the structure. Blitzmax instead uses a pointer to the arrays.


Haramanai(Posted 2010) [#5]
Azathoth thanks for the info. (But you are the blind idiot god and I don't know if I must believe you... Just kidding. )


So I must use C to make the wrap. I was hapy cause I thought that I can just import it with the LoadLibraryA and GetProcAdress.

I readed some books about C but never learned to use a DLL.

There isn't anywhere a simple and short example of how to do it?

A short example of how the C file looks like.( with the Include and all )