On Aug 19, 6:10*pm, cozumeldi...@comcast.net wrote:
I need to call the below function from a C# application. Having
problems converting it to C#. I think the BOOLs are just integers in
C#.
It will work, but you can also use "bool" just fine - it maps to 4-
byte WinAPI-style BOOL by default.
I have tried char[] and string for the PAWDOBJKEY. I always get
"ERROR_BAD_PARAM" for a return value.
* * SHORT APIENTRY AwdApiInsertItemKey(
* * * * * * * * * * *HWND hwndContainer,
* * * * * * * * * * *PAWDOBJKEY pAwdObjParentKey,
* * * * * * * * * * *PAWDOBJKEY pAwdObjKey,
* * * * * * * * * * *BOOL fUpdateCount,
* * * * * * * * * * *BOOL fLockFlag,
* * * * * * * * * * *PVOID pReserved);
* * Parameters
* * * hwndContainer: * *A handle to the container in which you want to
insert an item.
* * * pAwdObjParentKey: A pointer to the key of an existing parent of
the item to be inserted. If NULL, the item is inserted at the root.
* * * pAwdObjKey: * * * A pointer to the key of the item to insert. A view
call is made to get all the needed information to insert the item.
* * * fUpdateCount: * * This parameter is ignored.
* * * fLockFlag: * * * * * * * *Specifies whether or not to lock the object on
insertion. True=Lock False=Don’t Lock.
* * * pReserved: * * * * * * * *Reserved for futureuse; it should be NULL.
* =================
* * AWDOBJKEY
* * * Data that uniquely defines an AWD object. This data
distinguishes the object from other objects of the same type.
* * * Typedef struct awdobjkey
* * * * * * {
* * * * * * * CHAR crdattim [26];
* * * * * * * CHAR recordcd;
* * * * * * * CHAR crnode[2];
* * * * * * } AWDOBJKEY, *PAWDOBJKEY;
I don't see why you should use char[] or string for AWDOBJKEY, since
it's a struct. So you need to create a corresponding C# struct:
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
struct ADWOBJKEY
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=26)]
string crdattim;
char recordcd;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=2)]
string crnode;
}
And then PAWDOBJKEY is just a pointer, which (if you want to avoid
pointers in C#) translates to a "ref" argument of the method:
short AwdApiInsertItemKey(
* * * * * * * * * * IntPtr hwndContainer,
* * * * * * * * * * *ref AWDOBJKEY pAwdObjParentKey,
* * * * * * * * * * *ref AWDOBJKEY pAwdObjKey,
* * * * * * * * * * *bool fUpdateCount,
* * * * * * * * * * *bool fLockFlag,
* * * * * * * * * * *IntPtr pReserved);
Depending on whether the C++ code also includes some #pragma pack
directives (or is compiled with the corresponding compiler options),
you might also need to set StructLayoutAttribute.Size on the struct
declaration.