473,847 Members | 1,802 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.

PvcsGetArchiveI nfo( ARCHVIE_NOT_OPE N, "c:\\foo.c, v", null, null, null, null,
null, null, null, null, ref MyInt, null, null, null, null, null, null,
MyFlags)

[DllImport("vmwf dtk")]
public static extern int
PvcsGetArchiveI nfoVB1( 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_l ock, /* Output */
ref int attribute_wrt_p rot, /* Output */
ref int attribute_excl_ lock, /* Output */
ref int attribute_exp_k eys, /* Output */
ref int attribute_trans late, /* Output */
ref int attribute_cmprs _delta, /* Output */
ref int attribute_cmprs _text, /* Output */
long /*PVCS_FLAGS*/ flags);

If this helps, here is C Prototype:

PvcsGetArchiveI nfoVB1(ARCHIVEH ANDLE 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_l ock, /* Output */
unsigned short * attribute_wrt_p rot, /* Output */
unsigned short * attribute_excl_ lock, /* Output */
unsigned short * attribute_exp_k eys, /* Output */
unsigned short * attribute_trans late, /* Output */
unsigned short * attribute_cmprs _delta, /* Output */
unsigned short * attribute_cmprs _text, /* Output */
PVCS_FLAGS flags) /* Input */
Nov 17 '05 #1
5 3501
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.co m

"Bucky Pollard" <my***********@ ml.com> wrote in message
news:OB******** ******@TK2MSFTN GP15.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.

PvcsGetArchiveI nfo( ARCHVIE_NOT_OPE N, "c:\\foo.c, v", null, null, null,
null,
null, null, null, null, ref MyInt, null, null, null, null, null, null,
MyFlags)

[DllImport("vmwf dtk")]
public static extern int
PvcsGetArchiveI nfoVB1( 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_l ock, /* Output */
ref int attribute_wrt_p rot, /* Output */
ref int attribute_excl_ lock, /* Output */
ref int attribute_exp_k eys, /* Output */
ref int attribute_trans late, /* Output */
ref int attribute_cmprs _delta, /* Output */
ref int attribute_cmprs _text, /* Output */
long /*PVCS_FLAGS*/ flags);

If this helps, here is C Prototype:

PvcsGetArchiveI nfoVB1(ARCHIVEH ANDLE 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_l ock, /* Output */
unsigned short * attribute_wrt_p rot, /* Output */
unsigned short * attribute_excl_ lock, /* Output */
unsigned short * attribute_exp_k eys, /* Output */
unsigned short * attribute_trans late, /* 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******** ******@TK2MSFTN GP15.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.

PvcsGetArchiveI nfo( ARCHVIE_NOT_OPE N, "c:\\foo.c, v", null, null, null,
null,
null, null, null, null, ref MyInt, null, null, null, null, null, null,
MyFlags)

[DllImport("vmwf dtk")]
public static extern int
PvcsGetArchiveI nfoVB1( 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_l ock, /* Output */
ref int attribute_wrt_p rot, /* Output */
ref int attribute_excl_ lock, /* Output */
ref int attribute_exp_k eys, /* Output */
ref int attribute_trans late, /* Output */
ref int attribute_cmprs _delta, /* Output */
ref int attribute_cmprs _text, /* Output */
long /*PVCS_FLAGS*/ flags);

If this helps, here is C Prototype:

PvcsGetArchiveI nfoVB1(ARCHIVEH ANDLE 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_l ock, /* Output */
unsigned short * attribute_wrt_p rot, /* Output */
unsigned short * attribute_excl_ lock, /* Output */
unsigned short * attribute_exp_k eys, /* Output */
unsigned short * attribute_trans late, /* 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******** ******@TK2MSFTN GP15.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.

PvcsGetArchiveI nfo( ARCHVIE_NOT_OPE N, "c:\\foo.c, v", null, null, null,
null,
null, null, null, null, ref MyInt, null, null, null, null, null, null,
MyFlags)

[DllImport("vmwf dtk")]
public static extern int
PvcsGetArchiveI nfoVB1( 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_l ock, /* Output */
ref int attribute_wrt_p rot, /* Output */
ref int attribute_excl_ lock, /* Output */
ref int attribute_exp_k eys, /* Output */
ref int attribute_trans late, /* Output */
ref int attribute_cmprs _delta, /* Output */
ref int attribute_cmprs _text, /* Output */
long /*PVCS_FLAGS*/ flags);

If this helps, here is C Prototype:

PvcsGetArchiveI nfoVB1(ARCHIVEH ANDLE 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_l ock, /* Output */
unsigned short * attribute_wrt_p rot, /* Output */
unsigned short * attribute_excl_ lock, /* Output */
unsigned short * attribute_exp_k eys, /* Output */
unsigned short * attribute_trans late, /* Output */
unsigned short * attribute_cmprs _delta, /* Output */
unsigned short * attribute_cmprs _text, /* Output */
PVCS_FLAGS flags) /* Input */

Nov 17 '05 #4

"Ollie Riches" <ol**********@p honeanalyser.ne t> wrote in message
news:eI******** ******@TK2MSFTN GP14.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******** ******@TK2MSFTN GP09.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
3530
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 circular dependencies of DLL's. Does anyone know how to do this, I have tried everything in my book. I have a C++ function GetP: DllExport void GetP()
2
3028
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 convert it into C#. In VB we are using a function from the DLL whose signature is like : Declare Function RFVB_SendFiles1 Lib "RF2VB.DLL" (ByVal hServer As Long, _ ByVal lFI10Object As
2
6579
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 null terminated character array that is sent through the DllImport interface 'QtkSendMesg'. However, when I receive this struct in the C++ DLL, the character array that I passed to it is filled with random characters. What am I doing wrong when...
2
1697
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 the client-side API a generic API in ANSI/ISO C is written as well, and then wrappers for Perl, Objective-C, C++, COM, Java etc are written on top so that all developers can use whatever they feel comfortable with (Or more realistically what...
0
3842
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 print labels on the DYMO LabelWriter printer. Here is my C# code. Please let what am I doing wrong. This code is successfully compiled, but it does not work when you execute the final executable program. I have included the c structure and...
8
1792
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 ByRef to the functions. An unhandled exception of type 'System.Runtime.InteropServices.MarshalDirectiveExcept ion' occurred in ConsoleApplication1.exe Additional information: PInvoke restriction: can not
1
4489
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 *result_array, /* Returned adress of an array of uint16*/ uint16 *var_length_array, /*In call and Returned adress of an array uint16 */ void *value_array /* Returned, pointer of buffer provided by user
11
7198
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 VB in C# but it doens't work. c++: (csp2.dll) NoMangle long DLL_IMPORT_EXPORT csp2TimeStamp2Str(unsigned char *Stamp, char *value, long nMaxLength);
6
3885
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 definined as taking a char * as an argument? For example the C++ header says SDCERR GetCurrentConfig(DWORD *num, char *name); I am using Uint for the *num parameter, which returns the correct value but for *name, I always get back a string of 6 squares....
0
9730
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10983
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10647
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10706
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10338
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7056
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5719
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5911
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4528
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.