c++ to c# help

  • Thread starter Thread starter scany14
  • Start date Start date
S

scany14

Hi,

I am trying to convert the following c++ code to c#.


BYTE* pbmp = (BYTE*)malloc(lSize);;
myFunction((long)pbmp);


Can anyone help?

Many thanks.
 
Hello, (e-mail address removed)!

can you give us more context on your question?
What does myFunction() ?


These 2 lines of your code tell nothing about how
allocated memory is used.

That is why even the following code can be an answer to your question

byte[] bmp = new byte[size];
MyFunction(bmp);

s> I am trying to convert the following c++ code to c#.


s> BYTE* pbmp = (BYTE*)malloc(lSize);;
s> myFunction((long)pbmp);


s> Can anyone help?

s> Many thanks.


--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
MyFunction()

Expects a pointer to be passed pointing to the buffer.

As Vadym stated:
byte[] bmp = new byte[size];
MyFunction(bmp);

Will solve your problem based on all that you have told us.
Replace
BYTE* pbmp = (BYTE*)malloc(lSize);;
with
byte[] bmp = new byte[size];

// pbmp is a pointer to a dynamically allocated block of memory of size:
lSize
// bmp is a reference (think pointer) to a dynamically allocated array
of bytes of size: size

It is possible that you actually NEED to use pointers for your real
problem (they do exist in C#)
But, from what you have shown us....you have your solution.

Bill
 
Thanks for the attempts at help guys. Perhaps i didn't explain it
clearly enough. Maybe i should have started that the function was not
c# but a function to an external control.

I was able to do it using the following code:

byte[] buffer = new byte[Size];
fixed (byte* pBuffer = buffer)
{
myFunction((int)pBuffer);
}
 

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

Back
Top