[C#] P/Invoke and void*

G

Guest

Hi,

how can I translate in C# a void *.
I have a function which is : int myFunction (void *pSrcImage1, void
*pSrcImage2)
pSrcImage is a path to the Image.

I'd like to use it in C#.

Thanks

Fred
 
P

Paul G. Tobey [eMVP]

That depends on how it's actually used. You'll have to understand the
semantics of the call and choose an appropriate implementation based on
that. IntPtr might be one way to do it, for some situations. In other
cases, you might need to allocate some memory and pass that address of the
start of that array or unmanaged memory block.

Paul T.
 
G

Guest

Hi Paul,

thank you for your answer.
if I'd like to use System.IntPtr, I will declare this :
private static extern int myFunction(System.IntPtr pSrcIamgeFileName,
System.IntPtr pCorrectedIamgeFileName);

If I have two parameters which is :
string s1 = @"C:\img.jpg";
string s2 = @"C:\img2.jpg";

What is the syntax to call myFunction with this paramters ?
How can I provide a System.IntPtr from a string ?

Thank you

Fred
 
P

Paul G. Tobey [eMVP]

If those are the meanings of the parameters (filenames), why not just
declare them as accepting strings?

Paul T.
 
P

Paul G. Tobey [eMVP]

The only case where that might not work is if the function is expecting
strings composed of ASCII characters (8-bit), not Unicode characters
(16-bit). In that case, I'd declare the parameters as byte[]'s and use the
System.Text.ASCIIEncoding.GetBytes() to extract the ASCII versions of the
strings you need to pass from managed code.

Paul T.
 
G

Guest

Ok Paul thank you. I will test.

Fred

Paul G. Tobey said:
The only case where that might not work is if the function is expecting
strings composed of ASCII characters (8-bit), not Unicode characters
(16-bit). In that case, I'd declare the parameters as byte[]'s and use the
System.Text.ASCIIEncoding.GetBytes() to extract the ASCII versions of the
strings you need to pass from managed code.

Paul T.

Freddyboy said:
Hi paul,

Thank you, I take a look about this.

Best Regards
 
G

Guest

I found the solution.
byte[] str = System.Text.Encoding.ASCII.GetBytes(thepath");

Thank you.

Freddyboy said:
I don't know exactly how the call is supposed to work.
I give two parameters to the function and the first parameter (void*) is a
string which represent the source image file and a second parameter (void*)
which is also a string which represent the destination image file.

Before the call of my method, the image is not corrected. After the call of
the method, the image is corrected. There is a treatment to perform a
perspective correction on the image (the image is a receipt).

Is my small explanation help you ?

Thanks


Paul G. Tobey said:
***YOU HAVE TO KNOW HOW THE CALL IS SUPPOSED TO WORK***

If you don't know how the call is supposed to work, we cannot help you.
Based on your original message, it looks like you wrote the function you're
trying to call, no? How does it work?

Paul T.

Freddyboy said:
Hi,
I tested all your solutions. All solutions compiled but nothing execute
correctly the method.

You said : "That depends on how it's actually used. You'll have to
understand the semantics of the call and choose an appropriate
implementation
based on that. IntPtr might be one way to do it, for some situations. In
other cases, you might need to allocate some memory and pass that address
of
the start of that array or unmanaged memory block."

Could you give me an exemple please, because I have some difficulty ?

Thanks.

:

Ok Paul thank you. I will test.

Fred

:

The only case where that might not work is if the function is expecting
strings composed of ASCII characters (8-bit), not Unicode characters
(16-bit). In that case, I'd declare the parameters as byte[]'s and use
the
System.Text.ASCIIEncoding.GetBytes() to extract the ASCII versions of
the
strings you need to pass from managed code.

Paul T.

Hi paul,

Thank you, I take a look about this.

Best Regards

:

If those are the meanings of the parameters (filenames), why not
just
declare them as accepting strings?

Paul T.

Hi Paul,

thank you for your answer.
if I'd like to use System.IntPtr, I will declare this :
private static extern int myFunction(System.IntPtr
pSrcIamgeFileName,
System.IntPtr pCorrectedIamgeFileName);

If I have two parameters which is :
string s1 = @"C:\img.jpg";
string s2 = @"C:\img2.jpg";

What is the syntax to call myFunction with this paramters ?
How can I provide a System.IntPtr from a string ?

Thank you

Fred

:

That depends on how it's actually used. You'll have to
understand the
semantics of the call and choose an appropriate implementation
based
on
that. IntPtr might be one way to do it, for some situations. In
other
cases, you might need to allocate some memory and pass that
address of
the
start of that array or unmanaged memory block.

Paul T.

message
Hi,

how can I translate in C# a void *.
I have a function which is : int myFunction (void *pSrcImage1,
void
*pSrcImage2)
pSrcImage is a path to the Image.

I'd like to use it in C#.

Thanks

Fred
 

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

Similar Threads


Top