Hi! I'm having some doubts when trying to convert one data type to another. To be more specific, I'm trying to convert one
seq[byte]
to ptr DATA_BLOB
using winimConverterVarObjectToPtrObject
But I can't figure out what I'm doing wrong... I don't understood very well how to use this converter. Already tried some things but none of them worked and I couldn't understand the example on its page. Can someone help me?
I'm having some doubts
I do know nothing about winim, so maybe we should wait until its author can answer. But one hint: Looking at the source code of that converter, it is obvious that it is useless for seqs. Generally, when you have a seq, and want to pass the data to a C lib proc, you can use seq[0].addr. Maybe you have to cast it before to the right data type, like callMyCLibproc(castExpectedType])
Reason for this notation is, that seq stores additional information like length, and seq[0] is the first element, and often one passes the address of the first element to C functions.
A lot of Windows APIs accept "pointer to some structure" as parameters, for example (in C source):
MSG msg;
GetMessage(&msg, 0, 0, 0);
How to convert this code to nim?
var msg: MSG
GetMessage(addr msg, 0, 0, 0)
Ok, it is easy to understand. The only problem is that I am too lazy to add "addr" before each parameter. So with that converter, I can just write:
var msg: MSG
GetMessage(msg, 0, 0, 0)
This is the reason why the converter exists.
Ps. Technically speaking, I add this converter is because that I want make winim be compatible with winlean.nim. In winlean, this kind of parameters often are "var parameter", but winim follow the SDK definition so they are just "ptr object". For example:
# winlean
proc getSystemTimes*(lpIdleTime, lpKernelTime, lpUserTime: var FILETIME): WINBOOL
# winim
proc GetSystemTimes*(lpIdleTime, lpKernelTime, lpUserTime: ptr FILETIME): WINBOOL