Extending the Registry donated-code #2
"Christophe Bouhier (MC/ECM)" <[email protected]> Thu, 30 Jun 2005 18:29:03 +0800
| Newsgroups | gmane.comp.windows.devel.jawin |
|---|---|
| Message-ID | <54F404A6467B0242BBBE0E5EB405C295D80309@emyklmw104> |
Hello again,
I figured out the short-cut methods won't do the job. I have to call the generic
invoke method. The serialization is very challenging, I managed to do what I want,
without being to sure of what I am doing :) I would appreciate if someone can check if the
instruction string is correct and how to process a return value??
here is the code.
fpSKV = new FuncPtr("ADVAPI32.DLL", "RegSetValueExW");
public static void SetKeyValue(int key, String name, String value) throws IOException, COMException {
NakedByteStream nbs = new NakedByteStream();
// wrap it in a LittleEndianOutputStream
LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
// and then write the Java arguments
leos.writeInt(key); // 4 bytes.
leos.writeStringUnicode(name); // 4 bytes, this is PTR
leos.writeInt(0); // 4 bytes
leos.writeInt(1); // type like REG_NONE = 0, REG_SZ =1, REG_EXPAND_SZ=2 etc..
leos.writeStringUnicode(value);
leos.writeInt((value.length()*2));
// System.out.print("Stream length=" + nbs.size() );
fpSKV.invoke("IGIIGI:T1:", 24, nbs, null, ReturnFlags.CHECK_NONE);
// T1 throws exception with The operation completed successfully.
// T7 is no exception
}
Can I get CVS access to commit the Registry stub?
Cheers / Christophe
p.s. As an end-user of libraries it's a bit nuts I have to dive into this,
deploying java apps is just a bit more demanding ;-)