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
pSpec
could be a pointer to a buffer orNULL
, so I set it to aIntPtr.Zero
(documentation). - That
dwFlags
anddwReserved
according to the documentation "Must be set by the developer to 0". - That
pCallbackFunc
can be set toNULL
if 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 anIntPtr
withMarshal.AllocHGlobal(Marshal.SizeOf(instance))
, then getting the address value which is passed as auint
fordwCallbackData
and aIntPtr
forphExport
.
The final parameter list is as follows:
phDoc
as anIntPtr
which was loaded with an address by theDAOpenDocument
function called before.dwOutputId
asuint
set to1535
which representsFI_JPEGFIF
dwSpecType
asint
set to2
which representsIOTYPE_ANSIPATH
pSpec
as anIntPtr.Zero
where the output will be writtendwFlags
asuint
set to0
as directeddwReserved
asuint
set to0
as directedpCallbackFunc
asIntPtr
set toNULL
as I will handle resultsdwCallBackData
asuint
the address of a buffer for a structphExport
asIntPtr
to 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_PTR
is defined as:Which in turn is defined as:
The attribute
__int3264
is documented here, I am reproducing the most important bit:When you are marshaling C "types" such as
DWORD_PTR
whose 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 nameVTSYSPARAM
appears 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.