How to convert this code from C# to VB.NET?

C

Chris

When I run this code in VB.NET, it hangs on the GeneratePerlinTexture call.
I think it is because I am not calling it correctly.

The C# code that works:

[DllImport("PerlinDLL.dll")]
static extern unsafe void GeneratePerlinTexture(void *ARGB32_pixels, int w,
int h);

....later...

BitmapData bmData;
Rectangle rect = new Rectangle(0,0,bmp_ARGB32.Width,bmp_ARGB32.Height);
bmData = bmp_ARGB32.LockBits(rect, ImageLockMode.ReadWrite,
PixelFormat.Format32bppArgb);
GeneratePerlinTexture(bmData.Scan0.ToPointer(), bmp_ARGB32.Width,
bmp_ARGB32.Height);
bmp_ARGB32.UnlockBits(bmData);



What I've done in VB.NET:

Declare Sub GeneratePerlinTexture Lib "Perlindll.dll" Alias
"GeneratePerlinTexture" (ByVal ARGB32_pixels As System.IntPtr, ByVal x As
Integer, ByVal y As Integer)

....later...

Dim bmData As Drawing.Imaging.BitmapData
Dim rect = New Rectangle(0, 0, my_bitmap.Width, my_bitmap.Height)
bmData = my_bitmap.LockBits(rect, Imaging.ImageLockMode.ReadWrite,
Imaging.PixelFormat.Format32bppArgb)
GeneratePerlinTexture(bmData.Scan0, my_bitmap.Width, my_bitmap.Height)
'Hangs here
my_bitmap.UnlockBits(bmData)



I have the source code for the DLL if needed.
I cannot figure it out!
Thank you if you can help.

Chris
 
C

Crouchie1998

Chris

On this site somewhere is a list of C# to VB.NET convertors

Crouchie1998
BA (HONS) MCP MCSE
 
C

Chris

I've tried some converters, they do not work. Some just spit out the same
c# code with no explanation.
Thank you!
Chris
 
R

Ryan Chavez

I would just make sure that you values being passed to the
GeneratePerlinTexture are correct.
ie Make sure that my_bitmap.Width contains the actual width of the rect.
Chris said:
I've tried some converters, they do not work. Some just spit out the same
c# code with no explanation.
Thank you!
Chris
 
G

Guest

The on-line converters have a lot of issues - try our Instant VB C# to VB.NET
converter, downloadable from www.instantvb.com

David Anton
www.tangiblesoftwaresolutions.com
Home of:
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant J#: VB.NET to J# Converter

Chris said:
I've tried some converters, they do not work. Some just spit out the same
c# code with no explanation.
Thank you!
Chris
 
G

Guest

just a stab here, but the c# code has an unsafe void - i didnt think that
vb.net supported unsafe code. might that be the problem?

aware of my ignorance,
gabe
 

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

Top