473,396 Members | 1,774 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,396 software developers and data experts.

How to handle File Pointers (*File) from C++ dll?

Wes
Hello,

I am writing a class in C# that uses [DllImport("dllname.dll")] to call
functions from a C++ dll. Evenything seems to work fine call the functions
except one of the functions takes a *File as a parameter.

Many of the functions also used char* and int* and I used string and IntPtr
respectively. Does anyone know a way to handle the file pointers?

This is the C++ declaration:
CPP DEBUG_API int interpret_command(char *inString, FILE *inputFile);

And I want to use:
[DllImport("debug.dll")]
static extern int interpret_command(string command, ??What goes here??);

Thanks in advance for any help.

Wes
Nov 16 '05 #1
6 3591
"Wes" <We*@discussions.microsoft.com> wrote in message
news:55**********************************@microsof t.com...
Hello,

I am writing a class in C# that uses [DllImport("dllname.dll")] to call
functions from a C++ dll. Evenything seems to work fine call the
functions
except one of the functions takes a *File as a parameter.

Many of the functions also used char* and int* and I used string and
IntPtr
respectively. Does anyone know a way to handle the file pointers?

This is the C++ declaration:
CPP DEBUG_API int interpret_command(char *inString, FILE *inputFile);

And I want to use:
[DllImport("debug.dll")]
static extern int interpret_command(string command, ??What goes here??);
[DllImport("debug.dll")]
static extern int interpret_command(string command, IntPtr inputFile);

Thanks in advance for any help.

Wes

Nov 16 '05 #2
Wes
Hey Sean,

Thanks for the post. I tried using the IntPtr and I get an "Object
reference not set to an instance of an object." exception.

Here is what I tried.

[DllImport("debug.dll")]
static extern int interpret_command(string command, IntPtr file);

public void SomeFunction()
{
IntPtr filePointer = new IntPtr();
try
{
status = interpret_command("test command", filePointer);
}
catch(Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}

Does this seem right to you??

Thanks,
Wes

"Sean Hederman" wrote:
"Wes" <We*@discussions.microsoft.com> wrote in message
news:55**********************************@microsof t.com...
Hello,

I am writing a class in C# that uses [DllImport("dllname.dll")] to call
functions from a C++ dll. Evenything seems to work fine call the
functions
except one of the functions takes a *File as a parameter.

Many of the functions also used char* and int* and I used string and
IntPtr
respectively. Does anyone know a way to handle the file pointers?

This is the C++ declaration:
CPP DEBUG_API int interpret_command(char *inString, FILE *inputFile);

And I want to use:
[DllImport("debug.dll")]
static extern int interpret_command(string command, ??What goes here??);


[DllImport("debug.dll")]
static extern int interpret_command(string command, IntPtr inputFile);

Thanks in advance for any help.

Wes


Nov 16 '05 #3
Hi....

Try a ref. If memory serves, a FILE* is nothing more than a long* - so you
need a pointer (a ref in C#).

John Puopolo
"Wes" <We*@discussions.microsoft.com> wrote in message
news:55**********************************@microsof t.com...
Hello,

I am writing a class in C# that uses [DllImport("dllname.dll")] to call
functions from a C++ dll. Evenything seems to work fine call the functions except one of the functions takes a *File as a parameter.

Many of the functions also used char* and int* and I used string and IntPtr respectively. Does anyone know a way to handle the file pointers?

This is the C++ declaration:
CPP DEBUG_API int interpret_command(char *inString, FILE *inputFile);

And I want to use:
[DllImport("debug.dll")]
static extern int interpret_command(string command, ??What goes here??);

Thanks in advance for any help.

Wes

Nov 16 '05 #4
Wes
Hi John,

Thanks for the post.

This is what I tried after getting your post, and I still the error "Object
reference not set to an instance of an object."

[DllImport("debug.dll")]
static extern int interpret_command(string command, ref int file);

public void SomeFunction()
{
int filePointer = 0;

try
{
status = interpret_command("test command",ref filePointer);
}
catch(Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}

Can you see a problem with this??

"John Puopolo" wrote:
Hi....

Try a ref. If memory serves, a FILE* is nothing more than a long* - so you
need a pointer (a ref in C#).

John Puopolo
"Wes" <We*@discussions.microsoft.com> wrote in message
news:55**********************************@microsof t.com...
Hello,

I am writing a class in C# that uses [DllImport("dllname.dll")] to call
functions from a C++ dll. Evenything seems to work fine call the

functions
except one of the functions takes a *File as a parameter.

Many of the functions also used char* and int* and I used string and

IntPtr
respectively. Does anyone know a way to handle the file pointers?

This is the C++ declaration:
CPP DEBUG_API int interpret_command(char *inString, FILE *inputFile);

And I want to use:
[DllImport("debug.dll")]
static extern int interpret_command(string command, ??What goes here??);

Thanks in advance for any help.

Wes


Nov 16 '05 #5
I just assumed that FILE was a file handle. Is it maybe a struct or
something?

"Wes" <We*@discussions.microsoft.com> wrote in message
news:98**********************************@microsof t.com...
Hey Sean,

Thanks for the post. I tried using the IntPtr and I get an "Object
reference not set to an instance of an object." exception.

Here is what I tried.

[DllImport("debug.dll")]
static extern int interpret_command(string command, IntPtr file);

public void SomeFunction()
{
IntPtr filePointer = new IntPtr();
try
{
status = interpret_command("test command", filePointer);
}
catch(Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}

Does this seem right to you??

Thanks,
Wes

"Sean Hederman" wrote:
"Wes" <We*@discussions.microsoft.com> wrote in message
news:55**********************************@microsof t.com...
> Hello,
>
> I am writing a class in C# that uses [DllImport("dllname.dll")] to call
> functions from a C++ dll. Evenything seems to work fine call the
> functions
> except one of the functions takes a *File as a parameter.
>
> Many of the functions also used char* and int* and I used string and
> IntPtr
> respectively. Does anyone know a way to handle the file pointers?
>
> This is the C++ declaration:
> CPP DEBUG_API int interpret_command(char *inString, FILE *inputFile);
>
> And I want to use:
> [DllImport("debug.dll")]
> static extern int interpret_command(string command, ??What goes
> here??);


[DllImport("debug.dll")]
static extern int interpret_command(string command, IntPtr inputFile);
>
> Thanks in advance for any help.
>
> Wes


Nov 16 '05 #6
I assume that the function you are calling is expecting a valid file handle
to be passed in. You are passing in IntPtr.Zero which is the equivalent of a
null pointer. try to open a filestream and pass in the FileStream.Handle as
the argument.

"Wes" wrote:
Hey Sean,

Thanks for the post. I tried using the IntPtr and I get an "Object
reference not set to an instance of an object." exception.

Here is what I tried.

[DllImport("debug.dll")]
static extern int interpret_command(string command, IntPtr file);

public void SomeFunction()
{
IntPtr filePointer = new IntPtr();
try
{
status = interpret_command("test command", filePointer);
}
catch(Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}

Does this seem right to you??

Thanks,
Wes

"Sean Hederman" wrote:
"Wes" <We*@discussions.microsoft.com> wrote in message
news:55**********************************@microsof t.com...
Hello,

I am writing a class in C# that uses [DllImport("dllname.dll")] to call
functions from a C++ dll. Evenything seems to work fine call the
functions
except one of the functions takes a *File as a parameter.

Many of the functions also used char* and int* and I used string and
IntPtr
respectively. Does anyone know a way to handle the file pointers?

This is the C++ declaration:
CPP DEBUG_API int interpret_command(char *inString, FILE *inputFile);

And I want to use:
[DllImport("debug.dll")]
static extern int interpret_command(string command, ??What goes here??);


[DllImport("debug.dll")]
static extern int interpret_command(string command, IntPtr inputFile);

Thanks in advance for any help.

Wes


Nov 16 '05 #7

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

Similar topics

0
by: Kong Li | last post by:
Follow up to this thread, the latest Oracle 9i release 2 patchset (9.2.0.5) fixed the handle count leak problem. The problem is in Oracle client component. Thanks. Kong ----- From: Kong...
14
by: Howard | last post by:
Hi, I recently had a problem where I decided to store objects in a vector. (Previously, I had always stored pointers in vectors). Well, naturally, when storing an object in a vector, using...
13
by: Bonj | last post by:
Specifically, is there any difference between usin void MyFunction(const HANDLE myhandle an void MyFunction(const HANDLE& myhandleref ?? is the latter likely to cause problems (such as I...
7
by: Ioannis Vranos | last post by:
I have been checking C++/CLI lately by using VC++ 2005 Express Beta 1 (should be called Alpha though). In managed extensions we could pass managed pointers to functions taking unmanaged pointers...
5
by: Dinesh Kumar | last post by:
Hi all I am using VB.NET for a Connector dll in Delphi client and some webservice . can you tell me how to handle pointers in Vb.net which are passed by delphi client as parameters in function...
0
by: Dinesh Kumar | last post by:
Hi all I am using VB.NET for a Connector dll in Delphi client and some webservice . can you tell me how to handle pointers in Vb.net which are passed by delphi client as parameters in function...
2
by: Gary Wessle | last post by:
Hi I need help organizing this program in the right way. I included the code below which compiles and runs and gives the desired effect to a certain point, but I don't know what the next step...
2
weaknessforcats
by: weaknessforcats | last post by:
Handle Classes Handle classes, also called Envelope or Cheshire Cat classes, are part of the Bridge design pattern. The objective of the Bridge pattern is to separate the abstraction from the...
3
by: abhishek | last post by:
Hi group any idea on HOW TO HANDLE POINTERS FROM NON-LOCAL HEAPS?? Thank you
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.