News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

convert struct from c++

Started by jpam, January 02, 2011, 05:23:08 PM

Previous topic - Next topic

jpam

i hope someone can help me out with this
i don't kmow how to write the line below in masm
CONAGetDevices is a function inside dll
loaded with LoadLibrary and GetProcAddress

c++ syntax:
// Get list of currently connected devices
pDevices = new CONAPI_DEVICE[dwDeviceCount];
CONAGetDevices(hDMHandle, &dwDeviceCount, pDevices);


masm try:
CD  CONAPI_DEVICE <>
push offset CD ; offset struct
push iCount    ; 1
push phDMHandle ; handle from CONAOpenDM function
call _CONAGetDevices

eax returns 80100012 (ECONA_INVALID_POINTER)

pop eax
pop eax
pop eax


the handle from CONAOpenDM is correct
because CONAGetDeviceCount is returning ok

CONAPI_DEVICE and Connection_info are C++ struct's
// Device info structure
typedef struct
{
WCHAR* pstrSerialNumber;
WCHAR* pstrFriendlyName;
WCHAR* pstrModel;
WCHAR* pstrManufacturer;
DWORD dwNumberOfItems;
CONAPI_CONNECTION_INFO* pItems;
} CONAPI_DEVICE;

// Connection_info structure
typedef struct
{
DWORD dwDeviceID;
DWORD dwMedia;
WCHAR* pstrDeviceName;
WCHAR* pstrAddress;
DWORD dwState;
} CONAPI_CONNECTION_INFO;


i hoop i converted it right to masm syntax
CONAPI_DEVICE struct

pstrSerialNumber dd ?
pstrFriendlyName dd ?
pstrModel        dd ?
pstrManufacturer dd ?
dwNumberOfItems  dd ?
pItems           dd ?

CONAPI_DEVICE ends

CONAPI_CONNECTION_INFO struct

dwDeviceID dd ?
dwMedia    dd ?
pstrDeviceName dd ?
pstrAddress    dd ?
dwState    dd ?

CONAPI_CONNECTION_INFO ends

ToutEnMasm

translate correct , but it was useless to do it
Quote
; Device info structure

CONAPI_DEVICE   STRUCT
   pstrSerialNumber DWORD ?
   pstrFriendlyName DWORD ?
   pstrModel DWORD ?
   pstrManufacturer DWORD ?
   dwNumberOfItems DWORD ?
   pItems DWORD ?
CONAPI_DEVICE      ENDS


; Connection_info structure

CONAPI_CONNECTION_INFO   STRUCT
   dwDeviceID DWORD ?
   dwMedia DWORD ?
   pstrDeviceName DWORD ?
   pstrAddress DWORD ?
   dwState DWORD ?
CONAPI_CONNECTION_INFO      ENDS

result given by http://www.masm32.com/board/index.php?topic=5428.0

dedndave

the "*" means it is a pointer, if i remember C correctly
so, yes - it is a dword in 32 bit code
the prefix "pstr" means it is a pointer to a string
so - these are addresses

jpam

Thanks people

But if the struct's are correct,
how to deal with this C++ command ?
pDevices = new CONAPI_DEVICE[dwDeviceCount];

It looks like pDevices = pointer to Struct
i have try'ed many different inputs, like a pointer of a pointer, array of struct's and even memmory buffer
nothing is working,  still the same error invalid pointer 

qWord

Quote from: jpam on January 02, 2011, 07:51:57 PMhow to deal with this C++ command ?
pDevices = new CONAPI_DEVICE[dwDeviceCount];
should be:
mov eax,dwDeviceCount
imul eax,eax,SIZEOF CONAPI_DEVICE
mov pDevices,alloc(eax)


qWord
FPU in a trice: SmplMath
It's that simple!

clive

Not phDMAHandle?

CONAOpenDM
mov hDMHandle,eax

..

push hDMHandle ; handle from CONAOpenDM function

..
It could be a random act of randomness. Those happen a lot as well.

jpam

mov eax,dwDeviceCount
imul eax,eax,SIZEOF CONAPI_DEVICE
mov pDevices,alloc(eax)


Pointer to allocated memory
allready try that, error 80100012 (ECONA_INVALID_POINTER)

i got a brain dammage from this  :dazzled:

any ideas left   ::)

jpam

@clive

current code;
invoke GetProcessHeap
mov hHeap,eax

mov eax,iCount
imul eax,eax,SIZEOF CONAPI_DEVICE
invoke HeapAlloc,hHeap,HEAP_ZERO_MEMORY,eax
mov pMem,eax
mov pDevices,eax

push pDevices
push iCount
push phDMHandle
call _CONAGetDevices
PrintHex eax,"_CONAGetDevices"
pop eax
pop eax
pop eax

clive

Try getting the compiler to generate code for you to look at. Use -FAcs or check the compiler options.
It could be a random act of randomness. Those happen a lot as well.

dedndave

// Parameters:
//  hDMHandle [in]  Device manager handle
//  pdwCount [in,out] In: Number of allocated CONAPI_DEVICE structs.
// Out: Number of used CONAPI_DEVICE structs.
//  pDevices [out] Pointer to receiving CONAPI_DEVICE structures.


pdwCount is a pointer to a dword that holds the number of structures on input
and receives the number of used structures on output
you are passing the count, instead

jpam

dedndave you are right !

aarch !, bad manual reading from me  :(
when i pass the pointer of the dword its working !

many thanks all you people for helping me !
:U