ODM API calls from C# .NET

C

Cluggas

Really need some help with a problem that is bugging me.

I am trying to wrtie a C#.NET wrapper for the ODM (Open Document
Management)
API. I have written wrapping classes for other Windows API's in the
past in
VB6 and have not had a problem. However, VB6 is not a 'strictly typed'
language, and I think it is the type conversions from C# to the ODM
API that
is cauing my problem.

The following is an extract from the "ODMA.h" file that contains the
definitions of the ODM API

//----------------------------------------------------
ODMSTATUS WINAPI ODMSaveAsEx(ODMHANDLE odmHandle, LPSTR lpszDocId,
LPSTR lpszNewDocId, LPSTR lpszFormat, ODMSAVEASCALLBACK pcbCallBack,
LPVOID pInstanceData, LPDWORD pdwFlags);
//----------------------------------------------------

The following is my declaration in C# of this API function

//----------------------------------------------------
[DllImport("ODMA32.DLL", EntryPoint="ODMSaveAsEx")]
internal static extern Int16 ODMSaveAsEx
(
Int32 odmHandle,
string lpszDocId,
StringBuilder lpszNewDocId,
string lpszFormat,
Int32 pcbCallBack,
Int32 pInstanceData,
ref Int32 pdwFlags
);
//----------------------------------------------------

I am calling the API function via my declaration using the following
code

//----------------------------------------------------
/*
THESE 3 VARIABLES ARE ALREADY SET FROM PREVIOUS
CALLS TO OTHER ODM API METHODS
Int32 lngSessionID = //<The current session ID>//
string strDocID = //<The current document ID>//
string strDocumentFormat = //<The current docuemtn format>//
*/
Int16 intSuccess;
Int32 intCallBack = 0;
Int32 intInstanceData = 0;
Int32 intFlags = 0;
StringBuilder strBuffer = new StringBuilder(255);

intSuccess = ODMSaveAsEx (lngSessionID, strDocID,
strBuffer, strDocumentFormat, intCallBack,
intInstanceData, ref intFlags);
//----------------------------------------------------

When I run this call to "ODMSaveAsEx" I get the following error.

//----------------------------------------------------
An unhandled exception of type
'System.NullReferenceException' occurred in odmadocmanager.dll

Additional information:
Object reference not set to an instance of an object.
//----------------------------------------------------

Now I know what it looks like. I looks like I am passing a NULL
refernece to
this API call. This is not the case. I am absolutely sure that this
problem is
related to type compatability.

* Does anyone know of any specific Type conversion problems when
calling API's from C#?
* Has anyone ever done any development on the ODM API with .NET?

I know that you have to watch out for the following...

LONG (API world) = Int32 (.NET world)
INT (API world) = Int16 (.NET world)

....and I have tried to ensure that the correct type is used in my C#
code.
However, I am still stuck on this.
Can anyone help?

Much appreciated!!!
Cluggas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top