Hi,
Happy new year too!
I succeeded to have a working example. I wrote the code but I can't commit it.
Can you add me on the project please?
Just to give some indications for the code I changed.
Globally the primitive call is good. But when you pass 'nil' as argument for
the primitive, it will not be converted to 'null' ('null' have for value 0). To
have the 0, either you change nil into 0 or you add the option
#optCoerceNilToNull in the call (because it is not the default...) (See
'NBNativeCodeGen class>>defaultOptions' for the others). It is the mainly
problem!
Concerning the arguments allocation there is some tips:
'NativeBoost allocate: <number>' allocates a memory segment of the size given
by <number> and return the address to it.
But it is better to use 'NativeBoost allocate: (NBExternalType sizeOf:
'ulong')' or 'NativeBoost allocate: (NBExternalType sizeOf: 'DWORD')' for both
dwType and lSize arguments.
With some advance, you will see in the example4 that the RegQueryValueExA
doesn't return a valid error value... I don't know why...
I hope it will be helpful,
Cheers,
Vincent
-----Message d'origine-----
De : Pharo-dev [mailto:[email protected]] De la part de Torsten
Bergmann
Envoyé : dimanche 4 janvier 2015 21:43
À : Pharo Development List
Objet : [Pharo-dev] Wrapping RegQueryValueExA in NativeBoost
Hi,
Happy new year!
I try to wrap some API methods using NativeBoost to access Win32 Registry and
broaden the Pharo support for Windows. Currently I'm already able to
- create registry keys (RegCreateKeyA API)
- open registry keys (RegOpenKeyExA API)
- delete registry keys (RegDeleteKeyA API)
- close registry key handles (RegCloseKey API)
Now I additionally want to query some keys using the "RegQueryValueExA" API
(http://msdn.microsoft.com/en-us/library/windows/desktop/ms724911%28v=vs.85%29.aspx).
As I tried an example in an elder Smalltalk/MT first (see attached) I know it
is working from the Win32 API side.
My NativeBoost definition in Pharo for wrapping the function looks like this
(similar to MSDN):
regQueryValueExA: hKey with: lpValueName with: lpReserved with: lpType with:
lpData with: lpcbData
<primitive: 'primitiveNativeCall' module: 'NativeBoostPlugin'>
^ self nbCall: #(LONG RegQueryValueExA(
HKEY hKey,
LPCTSTR lpValueName,
LPDWORD lpReserved,
LPDWORD lpType,
LPBYTE lpData,
LPDWORD lpcbData)) module: #advapi32
But when I call it I get a "Generic error" thrown by NB and independent how
hard I try I can not get this call to work in NativeBoost. I checked all
arguments, checked the type definitions (pool WinTypes which is similar to
NBWinTypes), played with options, ... but was not able to find out what I'm
doing wrong in Pharo. Meanwhile after investing several days of my spare time
it looks like I cant "see the wood because of all the trees".
I would really appreciate if someone with enough knowledge of NativeBoost could
have a second look to point my into the right direction.
To reproduce:
=============
- use a fresh Pharo4.0 Latest update: #40428
- open World menu -> Configuration Browser and load "OSWindows" project
- go to class WinRegistry
- there is the NativeBoost API definition in method
#regQueryValueExA:with:with:with:with:with:
- and a method #example2 that calls this in a similar way as in my
Smalltalk/MT example
(if you try this example you get the "Generic error")
Many thanks in advance!
Bye
T.
Ce message et les pièces jointes sont confidentiels et réservés à l'usage
exclusif de ses destinataires. Il peut également être protégé par le secret
professionnel. Si vous recevez ce message par erreur, merci d'en avertir
immédiatement l'expéditeur et de le détruire. L'intégrité du message ne pouvant
être assurée sur Internet, la responsabilité de Worldline ne pourra être
recherchée quant au contenu de ce message. Bien que les meilleurs efforts
soient faits pour maintenir cette transmission exempte de tout virus,
l'expéditeur ne donne aucune garantie à cet égard et sa responsabilité ne
saurait être recherchée pour tout dommage résultant d'un virus transmis.
This e-mail and the documents attached are confidential and intended solely for
the addressee; it may also be privileged. If you receive this e-mail in error,
please notify the sender immediately and destroy it. As its integrity cannot be
secured on the Internet, the Worldline liability cannot be triggered for the
message content. Although the sender endeavours to maintain a computer
virus-free network, the sender does not warrant that this transmission is
virus-free and will not be liable for any damages resulting from any virus
transmitted.