Trying to Interop a functionality from the Outside In API from Oracle. Have the following function:
SCCERR EXOpenExport(VTHDOC hDoc, VTDWORD dwOutputId, VTDWORD dwSpecType,
VTLPVOID pSpec, VTDWORD dwFlags, VTSYSPARAM dwReserved,
VTLPVOID pCallbackFunc, VTSYSPARAM dwCallbackData, VTLPHEXPORT phExport);
From the header files I reduced the parameters to:
#define VTVOID void
typedef VTSYSPARAM VTHDOC, VTLPHDOC *;
typedef DWORD_PTR VTSYSPARAM;
typedef unsigned long DWORD_PTR;
typedef unsigned long VTDWORD;
typedef VTVOID* VTLPVOID;
typedef VTHDOC VTHEXPORT, *VTLPEXPORT;
These are for 32 bit windows.
Going through the header files, the example programs, and the documentation I found:
- That
pSpeccould be a pointer to a buffer orNULL, so I set it to aIntPtr.Zero(documentation). - That
dwFlagsanddwReservedaccording to the documentation "Must be set by the developer to 0". - That
pCallbackFunccan be set toNULLif I don't want to handle callbacks. - That the last two are based on structs that I wrote C# wrappers for using the
[StructLayout(LayoutKind.Sequential)]. Then instatiated an instance and generated the parameters by first creating anIntPtrwithMarshal.AllocHGlobal(Marshal.SizeOf(instance)), then getting the address value which is passed as auintfordwCallbackDataand aIntPtrforphExport.
The final parameter list is as follows:
phDocas anIntPtrwhich was loaded with an address by theDAOpenDocumentfunction called before.dwOutputIdasuintset to1535which representsFI_JPEGFIFdwSpecTypeasintset to2which representsIOTYPE_ANSIPATHpSpecas anIntPtr.Zerowhere the output will be writtendwFlagsasuintset to0as directeddwReservedasuintset to0as directedpCallbackFuncasIntPtrset toNULLas I will handle resultsdwCallBackDataasuintthe address of a buffer for a structphExportasIntPtrto another struct buffer
Still get an undefined error from the API. Meaning that the call returns a 961 which is not defined in any of the header files. In the past I have gotten this when my choice of parameter types are incorrect.
I started out using Interop Assistant which was helpful in learning how many of the parameter types get translated. It is however limited by how well I am able to glean the correct native type from the header files. For example the hDoc parameter used in the preceding function was defined as a non-filesytem handle, so attempted to use Marshal to create a handle, then used an IntPtr, and finally it turned out to be an int (actually it was &phDoc used here).
So is there a more scientific way of doing this, other than trial and error?
Jim
Your definition:
Is incorrect —
DWORD_PTRis defined as:Which in turn is defined as:
The attribute
__int3264is documented here, I am reproducing the most important bit:When you are marshaling C "types" such as
DWORD_PTRwhose size depends on the platform pointer size which is often the case with the OS parameters (such asLPARAM,WPARAM,LRESULT,SIZE_T, etc) which the nameVTSYSPARAMappears to suggest, you should useIntPtr, notuint.Basically:
Should be:
Then it should work, and if it doesn't you need to make sure you didn't make a similar mistake when marshaling the necessary structures.