Need to marshal the following C function to C#

B

BuddyWork

C function syntax is

PvcsGetRevisionInfo2(
HANDLE hArchive, /*Input */
unsigned char *filename, /*Input*/
unsigned char *revision, /*Input*/
unsigned char **author, /*Output*/
unsigned char **versions, /*Output*/
unsigned char **promoGroups, /*Output*/
unsigned char **lockers, /*Output*/
unsigned char **descr, /*Output*/
unsigned char *resultbuf, /*Input*/
unsigned bufLen, /*Input*/
void *reserved)

Please can you help to convert this syntax to C#.
 
T

Tasos Vogiatzoglou

void PvcsGetRevisionInfo2(
ref int hArchive,
string filename,
string revision,
ref string author,
ref string versions,
ref string promoGroups,
ref string lockers,
ref string descr,
string resultbuf,
int bufLen,
IntPtr reserved);

I think ...
 
T

Tasos Vogiatzoglou

char* is string ... A safe assumption would be that char ** is a
reference to a string ...
 
B

BuddyWork

I forgot to state the following about the parameters

versions (Output). Pointer to a pointer to a list of
strings. Each is a version label associated with
this revision. If Developer's Toolkit returns a
null pointer, then no version labels are
present.

promoGroups (Output). Pointer to a pointer to a list of
strings. Each string is a promotion group
associated with this revision. The strings are
null-separated with a double-null pointer at
the end of the list. Developer's Toolkit returns
a null pointer if no promotion groups are
present.

lockers (Output). Pointer to a pointer to a list of
strings. Each is a user ID that owns a lock on
the revision. The strings for these are nullseparated
with a double-null pointer at the
end of the list. Developer's Toolkit returns a
null pointer if no locks are present.

descr (Output). Pointer to a pointer to a string: the
revision change description. If Developer's
Toolkit returns a null pointer, then no change
description is present.

resultBuf Pointer to a buffer that this function uses to
store the result data. Your program must
allocate the buffer. The pointers referenced
by author, versions, promoGroups, lockers, and
description will point to memory in resultBuffer.

bufLen Length of the result buffer.

reserved Reserved for future use. Must be null.
 
G

Guest

You have a bigger problem in that 'C' strings do not map directly to C#
strings. A 'C' is a set of characters terminated by the null (0x00)
character. Where as a C# string has an associated length but is not
terminated by a null character (nulls are legal characters in C# strings).
The normal method of string transfer between C# and 'C' or 'C++' is to use
marshalling. Arrays are another area where 'C' or 'C++' and C# differ.
Because of the dynamic memory characteristics of C# marshalling again is
important. Given a little more time, I can dig up an example for you if you
can not resolve the issue.

Pat
 
B

BuddyWork

Thanks for the reply,

I've think I've sovled the problem, I need to do more testing

Here is the converted C to C# function
[DllImport("VMWFDTK.DLL")]
public static extern PVCS_E PvcsGetRevisionInfo2(
IntPtr logHandle, /* I: Archive handle */
string fileName, /* I: Name of logfile or workfile */
string revision, /* I: Revision to retrieve */
ref string author, /* O: Userid that created revision */
ref IntPtr versions, /* O: Version labels assigned to revision */
ref IntPtr promoGroups, /* O: Promotion groups assigned to revision
*/
ref IntPtr lockers, /* O: Userids that own a lock on revision */
ref string descr, /* O: Change description for revision */
IntPtr resultBuf, /* I: Buffer to contain results */
int bufLen, /* I: Length of buffer */
IntPtr reserved); /* Reserved for future use */

For the parameters that are pointer to a pointer I've used the Marshal
object to loop through and retrieve the string by checking for the null
pointer.
 

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