pinters to structs etc...
BlitzMax Forums/BlitzMax Programming/pinters to structs etc...
| ||
I am returning a pointer to a type:Type PmDeviceInfo Field structVersion:Int Field interf:Byte Ptr Field name:Byte Ptr Field Input:Int Field output:Int Field opened:Int EndType the values I get returned seem ok but I am having trouble accessing the fields interf and name. I use this code to print the returned strings: Global deviceinfo:PmDeviceInfo = New PmDeviceInfo MemCopy( Byte Ptr(deviceinfo), Pm_GetDeviceInfo(0), SizeOf(PmDeviceInfo) ) DebugLog "version = " + deviceinfo.structVersion DebugLog "interf = " + String.FromCstring(Varptr(deviceinfo.interf)) DebugLog "name = " + String.FromCstring(Varptr(deviceinfo.name)) I think the debuglog is trying to print the variable and not the string pointed to by the variable? any suggestions? please. |
| ||
DebugLog "interf = " + String.FromCstring(deviceinfo.interf) DebugLog "name = " + String.FromCstring(deviceinfo.name) ?? |
| ||
DebugLog "interf = " + String.FromCstring(deviceinfo.interf) DebugLog "name = " + String.FromCstring(deviceinfo.name) these two lines should print the string retuned in the structure PmDeviceInfo, the problem I feel is that deviceinfo.name and deviceinfo.interf are (byte ptr) not actual C strings. I have now uploaded the BlitzMAX module and test application to the website if you want to try it? |
| ||
What is it then if not C string? Either it is a 0 terminated char array ( memory block ) -> C String or it isn't. In the later case it would mean that it is a structure itself ... |
| ||
the pointer returned from the call to Pm_GetDeviceInfo() is a pointer to a struct of type: typedef struct { int structVersion; const char* interf; const char* name; int input; int output; int opend; } my blitz interpretation of this is: Type PmDeviceInfo Field structVersion:Int Field interf:Byte Ptr Field name:Byte Ptr Field Input:Int Field output:Int Field opened:Int EndType so all I want to do is print the strings pointed to by interf and name? |