473,320 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Passing NULL to a DLLImport function.

I am calling a PVCS DLL function from C#. According to the documentation, I
can pass NULL to any output parameter that I do not want to receive data
back for. How do I do this? Every thing I've tried results in a compiler
error.

TIA:
Bucky Pollard

My declaration is below. I am only looking for one piece of information, so
ultimately I'd like to call the function something like this.

PvcsGetArchiveInfo( ARCHVIE_NOT_OPEN, "c:\\foo.c,v", null, null, null, null,
null, null, null, null, ref MyInt, null, null, null, null, null, null,
MyFlags)

[DllImport("vmwfdtk")]
public static extern int
PvcsGetArchiveInfoVB1( long /*ARCHIVEHANDLE*/ hArchive, /* Input */
string fileName, /* Input */
ref int revcnt, /* Output */
ref int lockers, /* Output */
StringBuilder archive, /* Output */
StringBuilder workfile, /* Output */
StringBuilder owner, /* Output */
StringBuilder access, /* Output */
StringBuilder create_time, /* Output */
ref int attribute_chk_lock, /* Output */
ref int attribute_wrt_prot, /* Output */
ref int attribute_excl_lock, /* Output */
ref int attribute_exp_keys, /* Output */
ref int attribute_translate, /* Output */
ref int attribute_cmprs_delta, /* Output */
ref int attribute_cmprs_text, /* Output */
long /*PVCS_FLAGS*/ flags);

If this helps, here is C Prototype:

PvcsGetArchiveInfoVB1(ARCHIVEHANDLE hArchive, /* Input */
unsigned char * fileName, /* Input */
unsigned short * revcnt, /* Output */
unsigned short * lockers, /* Output */
unsigned char * archive, /* Output */
unsigned char * workfile, /* Output */
unsigned char * owner, /* Output */
unsigned char * access, /* Output */
unsigned char * create_time, /* Output */
unsigned short * attribute_chk_lock, /* Output */
unsigned short * attribute_wrt_prot, /* Output */
unsigned short * attribute_excl_lock, /* Output */
unsigned short * attribute_exp_keys, /* Output */
unsigned short * attribute_translate, /* Output */
unsigned short * attribute_cmprs_delta, /* Output */
unsigned short * attribute_cmprs_text, /* Output */
PVCS_FLAGS flags) /* Input */
Nov 17 '05 #1
5 3440
Bucky,

First, you should make sure your declaration is correct. You are using
a 64-bit value for the first parameter, which I don't think you really want.

As for passing in nulls, it would be easiest to do this using unsafe
code. You could declare the parameters as pointer types, and then pass 0 or
maybe null for the parameter you don't want to be set on output.

Finally, you should explicitly state that the CharSet is Ansi, since you
are using 8-bit character values.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bucky Pollard" <my***********@ml.com> wrote in message
news:OB**************@TK2MSFTNGP15.phx.gbl...
I am calling a PVCS DLL function from C#. According to the documentation, I
can pass NULL to any output parameter that I do not want to receive data
back for. How do I do this? Every thing I've tried results in a compiler
error.

TIA:
Bucky Pollard

My declaration is below. I am only looking for one piece of information,
so
ultimately I'd like to call the function something like this.

PvcsGetArchiveInfo( ARCHVIE_NOT_OPEN, "c:\\foo.c,v", null, null, null,
null,
null, null, null, null, ref MyInt, null, null, null, null, null, null,
MyFlags)

[DllImport("vmwfdtk")]
public static extern int
PvcsGetArchiveInfoVB1( long /*ARCHIVEHANDLE*/ hArchive, /* Input */
string fileName, /* Input */
ref int revcnt, /* Output */
ref int lockers, /* Output */
StringBuilder archive, /* Output */
StringBuilder workfile, /* Output */
StringBuilder owner, /* Output */
StringBuilder access, /* Output */
StringBuilder create_time, /* Output */
ref int attribute_chk_lock, /* Output */
ref int attribute_wrt_prot, /* Output */
ref int attribute_excl_lock, /* Output */
ref int attribute_exp_keys, /* Output */
ref int attribute_translate, /* Output */
ref int attribute_cmprs_delta, /* Output */
ref int attribute_cmprs_text, /* Output */
long /*PVCS_FLAGS*/ flags);

If this helps, here is C Prototype:

PvcsGetArchiveInfoVB1(ARCHIVEHANDLE hArchive, /* Input */
unsigned char * fileName, /* Input */
unsigned short * revcnt, /* Output */
unsigned short * lockers, /* Output */
unsigned char * archive, /* Output */
unsigned char * workfile, /* Output */
unsigned char * owner, /* Output */
unsigned char * access, /* Output */
unsigned char * create_time, /* Output */
unsigned short * attribute_chk_lock, /* Output */
unsigned short * attribute_wrt_prot, /* Output */
unsigned short * attribute_excl_lock, /* Output */
unsigned short * attribute_exp_keys, /* Output */
unsigned short * attribute_translate, /* Output */
unsigned short * attribute_cmprs_delta, /* Output */
unsigned short * attribute_cmprs_text, /* Output */
PVCS_FLAGS flags) /* Input */

Nov 17 '05 #2
I guess there is several ways to do this. One would be to modify the interop
library:

http://msdn.microsoft.com/library/de...opassembly.asp

HTH

Ollie Riches
"Bucky Pollard" <my***********@ml.com> wrote in message
news:OB**************@TK2MSFTNGP15.phx.gbl...
I am calling a PVCS DLL function from C#. According to the documentation, I
can pass NULL to any output parameter that I do not want to receive data
back for. How do I do this? Every thing I've tried results in a compiler
error.

TIA:
Bucky Pollard

My declaration is below. I am only looking for one piece of information,
so
ultimately I'd like to call the function something like this.

PvcsGetArchiveInfo( ARCHVIE_NOT_OPEN, "c:\\foo.c,v", null, null, null,
null,
null, null, null, null, ref MyInt, null, null, null, null, null, null,
MyFlags)

[DllImport("vmwfdtk")]
public static extern int
PvcsGetArchiveInfoVB1( long /*ARCHIVEHANDLE*/ hArchive, /* Input */
string fileName, /* Input */
ref int revcnt, /* Output */
ref int lockers, /* Output */
StringBuilder archive, /* Output */
StringBuilder workfile, /* Output */
StringBuilder owner, /* Output */
StringBuilder access, /* Output */
StringBuilder create_time, /* Output */
ref int attribute_chk_lock, /* Output */
ref int attribute_wrt_prot, /* Output */
ref int attribute_excl_lock, /* Output */
ref int attribute_exp_keys, /* Output */
ref int attribute_translate, /* Output */
ref int attribute_cmprs_delta, /* Output */
ref int attribute_cmprs_text, /* Output */
long /*PVCS_FLAGS*/ flags);

If this helps, here is C Prototype:

PvcsGetArchiveInfoVB1(ARCHIVEHANDLE hArchive, /* Input */
unsigned char * fileName, /* Input */
unsigned short * revcnt, /* Output */
unsigned short * lockers, /* Output */
unsigned char * archive, /* Output */
unsigned char * workfile, /* Output */
unsigned char * owner, /* Output */
unsigned char * access, /* Output */
unsigned char * create_time, /* Output */
unsigned short * attribute_chk_lock, /* Output */
unsigned short * attribute_wrt_prot, /* Output */
unsigned short * attribute_excl_lock, /* Output */
unsigned short * attribute_exp_keys, /* Output */
unsigned short * attribute_translate, /* Output */
unsigned short * attribute_cmprs_delta, /* Output */
unsigned short * attribute_cmprs_text, /* Output */
PVCS_FLAGS flags) /* Input */

Nov 17 '05 #3
It's just impossible to tell from the C function declaration how your
DllImport signature should look like, but you should keep in mind that
shorts in C are shorts in C# too, longs in C are int's in C#, handles are
IntPtr, so this is something you should correct first. Leaves us with
PVCS_FLAGS, which is IMO NOT a long in C#.

Willy.

"Bucky Pollard" <my***********@ml.com> wrote in message
news:OB**************@TK2MSFTNGP15.phx.gbl...
I am calling a PVCS DLL function from C#. According to the documentation, I
can pass NULL to any output parameter that I do not want to receive data
back for. How do I do this? Every thing I've tried results in a compiler
error.

TIA:
Bucky Pollard

My declaration is below. I am only looking for one piece of information,
so
ultimately I'd like to call the function something like this.

PvcsGetArchiveInfo( ARCHVIE_NOT_OPEN, "c:\\foo.c,v", null, null, null,
null,
null, null, null, null, ref MyInt, null, null, null, null, null, null,
MyFlags)

[DllImport("vmwfdtk")]
public static extern int
PvcsGetArchiveInfoVB1( long /*ARCHIVEHANDLE*/ hArchive, /* Input */
string fileName, /* Input */
ref int revcnt, /* Output */
ref int lockers, /* Output */
StringBuilder archive, /* Output */
StringBuilder workfile, /* Output */
StringBuilder owner, /* Output */
StringBuilder access, /* Output */
StringBuilder create_time, /* Output */
ref int attribute_chk_lock, /* Output */
ref int attribute_wrt_prot, /* Output */
ref int attribute_excl_lock, /* Output */
ref int attribute_exp_keys, /* Output */
ref int attribute_translate, /* Output */
ref int attribute_cmprs_delta, /* Output */
ref int attribute_cmprs_text, /* Output */
long /*PVCS_FLAGS*/ flags);

If this helps, here is C Prototype:

PvcsGetArchiveInfoVB1(ARCHIVEHANDLE hArchive, /* Input */
unsigned char * fileName, /* Input */
unsigned short * revcnt, /* Output */
unsigned short * lockers, /* Output */
unsigned char * archive, /* Output */
unsigned char * workfile, /* Output */
unsigned char * owner, /* Output */
unsigned char * access, /* Output */
unsigned char * create_time, /* Output */
unsigned short * attribute_chk_lock, /* Output */
unsigned short * attribute_wrt_prot, /* Output */
unsigned short * attribute_excl_lock, /* Output */
unsigned short * attribute_exp_keys, /* Output */
unsigned short * attribute_translate, /* Output */
unsigned short * attribute_cmprs_delta, /* Output */
unsigned short * attribute_cmprs_text, /* Output */
PVCS_FLAGS flags) /* Input */

Nov 17 '05 #4

"Ollie Riches" <ol**********@phoneanalyser.net> wrote in message
news:eI**************@TK2MSFTNGP14.phx.gbl...
I guess there is several ways to do this. One would be to modify the
interop library:

http://msdn.microsoft.com/library/de...opassembly.asp

HTH

Ollie Riches


Hmmm... the OP is talking about PInvoke interop not COM interop.

Willy.
Nov 17 '05 #5
Thank you to all the replies. I did have to change the ARCHIVEHANDLE
variable to a UIntPtr. IntPtr was getting mathematic errors, which I assumed
were overflows, but didn't research further. All other variables are working
as it, but it seems it would be good form to change the ints to shorts and
the longs to ints.

So the function works, but the issue is I have to create and pass 8 shorts
and 5 StringBuilders for information I really do not care about. I'm not
sure about the overhead on the C# side, but am wondering if the "pointer" is
NULL on the receiving function, if the function does't extract that
information from archive (which is I/O which is overhead).

Also, instead of declaring

ref short lockers

should I code (will it work and is it better form)

out short lockers?

Thanks again,

Bucky.
(Long time C++ coder, short time C# coder and missing pointers)

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:u3**************@TK2MSFTNGP09.phx.gbl...
It's just impossible to tell from the C function declaration how your
DllImport signature should look like, but you should keep in mind that
shorts in C are shorts in C# too, longs in C are int's in C#, handles are
IntPtr, so this is something you should correct first. Leaves us with
PVCS_FLAGS, which is IMO NOT a long in C#.

Willy.


Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Adrian | last post by:
I am trying to pass the address of a C++ function into a Fortran routine to enable the Fortran routine to call this C++ function. I have to do it this way as our build process does not allow...
2
by: Manish | last post by:
Hi, I m facing a problem in re-writing a code from VB to C #. We are using a third party DLL to develop a application of Fax. The current application is already written in VB and we have to...
2
by: Chris | last post by:
Hi, I seem to be having a problem I can't quite figure out. Currently, I have the following code (below). In the SendMsg function, I create a 'Qtkmsg' which converts the string 'text' into a...
2
by: Fredrik Olsson | last post by:
Hello I am developing a cross-platform solution for scheduled messages, primary for SMS. The server parts are written in ASNI/ISO C to compile and run cleanly on any POSIX compatible server. For...
0
by: nygiantswin2005 | last post by:
I am tring to write simple console application in C# to test the APIs functions made available by the dymo sdk. The dymo sdk provides a dll library that can be used to call functions that will...
8
by: Bryan G | last post by:
Hi, I'm working on a VB project which involves using C library functions which take struct pointers as args, and I keep running into this error when trying to pass either an IntPtr or a Structure...
1
by: dumliks | last post by:
Hi, I have some problems with marshaling data to and from C DLL file; C definitoin for function is: int32 s7_get_multiple_read_cnf( void *od_ptr, /* In call, must be null*/ uint16...
11
by: Bob Yang | last post by:
Hi, I have this in C++ and I like to call it from c# to get the value but I fail. it will be good if you can give me some information. I tried it in VB.net it works but I use almost the same way as...
6
by: Andy Baker | last post by:
I am attempting to write a .NET wrapper for a C++ DLL file, but am having problems with passing strings as parameters. How should I be writing my C# function call when the C header file is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.