Click here to Skip to main content
15,887,027 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionCustom control , custom properties Pin
udikantz14-Mar-09 0:06
udikantz14-Mar-09 0:06 
AnswerRe: Custom control , custom properties [modified] Pin
Eddy Vluggen15-Mar-09 1:54
professionalEddy Vluggen15-Mar-09 1:54 
QuestionArray Example Help Pin
StarTrekCafe13-Mar-09 16:40
StarTrekCafe13-Mar-09 16:40 
AnswerRe: Array Example Help Pin
Christian Graus14-Mar-09 8:26
protectorChristian Graus14-Mar-09 8:26 
AnswerRe: Array Example Help Pin
StarTrekCafe14-Mar-09 13:47
StarTrekCafe14-Mar-09 13:47 
Questionhow can i change messagebox background color in windows applications ? Pin
pramod251713-Mar-09 10:33
pramod251713-Mar-09 10:33 
AnswerRe: how can i change messagebox background color in windows applications ? Pin
Luc Pattyn13-Mar-09 12:34
sitebuilderLuc Pattyn13-Mar-09 12:34 
QuestionMaking changes to an unmanaged struct from VB.NET Pin
Kurt Richardson13-Mar-09 9:52
Kurt Richardson13-Mar-09 9:52 
Hi All

I wonder if any one can help me figure out (or just plain tell me) how to make changes to an unmanaged struct created by a C++ DLL from VB.NET.

I think I understand how to make a copy of it, and then makes changes to the copy.

The structure in VB (which matches the unmanaged struct created from the C++ DLL) is:

<StructLayout(LayoutKind.Sequential)> _
    Public Structure passedStruct
        <MarshalAs(UnmanagedType.U4)> Dim IntNumber As UInt32
        <MarshalAs(UnmanagedType.U4)> Dim IntAnother As UInt32
        <MarshalAs(UnmanagedType.U4)> Dim ptr2Integer As UInt32
    End Structure


I call a function in the C++ DLL that creates a version of the struct, populates it, and returns the ptr to it. I can then make a copy just by something like:

Dim receivedStruct As passedStruct = Marshal.PtrToStructure(ptr, GetType(passedStruct))


This works fine and I can even pass the pointer of the copy back to the C++ DLL and have changes made from the DLL.

However, I'd like to do this the other way around to. I would like for the VB.NET application to receive the pointer from the C++ DLL and then make changes directly to the unmanaged version of the struct rather than making a copy of it. In C++ this is pretty easy, for example:

extern "C" __declspec(dllexport) void ChangeStruct(struct MyStruct * pMyStruct)
{

	pMyStruct->IntNumber += 23;

}


which just receives the pointer from VB.NET of a structure created in VB.NET and makes changes to it directly. MyStruct is defined as:

struct MyStruct {
	unsigned int IntNumber;
	unsigned int IntAnother;
	unsigned int IntYetAnother;
};


Does anyone know how to do this same thing in VB.NET?

Many thanks indeed for your assistance.

Kurt
AnswerRe: Making changes to an unmanaged struct from VB.NET Pin
Luc Pattyn13-Mar-09 10:23
sitebuilderLuc Pattyn13-Mar-09 10:23 
GeneralRe: Making changes to an unmanaged struct from VB.NET Pin
Kurt Richardson13-Mar-09 10:52
Kurt Richardson13-Mar-09 10:52 
GeneralRe: Making changes to an unmanaged struct from VB.NET Pin
Luc Pattyn13-Mar-09 11:10
sitebuilderLuc Pattyn13-Mar-09 11:10 
GeneralRe: Making changes to an unmanaged struct from VB.NET Pin
Kurt Richardson13-Mar-09 11:38
Kurt Richardson13-Mar-09 11:38 
QuestionAsk For Image Location? [modified] Pin
Schoof13-Mar-09 9:05
Schoof13-Mar-09 9:05 
AnswerRe: Ask For Image Location? Pin
Dave Kreskowiak15-Mar-09 3:32
mveDave Kreskowiak15-Mar-09 3:32 
QuestionNEED 1 VB PROGRAMMER TO DEVELEP SOME SAMLL PROGRAMES FOR MY BUSINESS Pin
carlhaley13-Mar-09 7:11
carlhaley13-Mar-09 7:11 
AnswerRe: NEED 1 VB PROGRAMMER TO DEVELEP SOME SAMLL PROGRAMES FOR MY BUSINESS Pin
Xmen Real 13-Mar-09 8:34
professional Xmen Real 13-Mar-09 8:34 
AnswerRe: NEED 1 VB PROGRAMMER TO DEVELEP SOME SAMLL PROGRAMES FOR MY BUSINESS Pin
Dave Kreskowiak13-Mar-09 8:44
mveDave Kreskowiak13-Mar-09 8:44 
AnswerRe: NEED 1 VB PROGRAMMER TO DEVELEP SOME SAMLL PROGRAMES FOR MY BUSINESS Pin
Dave Kreskowiak13-Mar-09 8:47
mveDave Kreskowiak13-Mar-09 8:47 
GeneralRe: NEED 1 VB PROGRAMMER TO DEVELEP SOME SAMLL PROGRAMES FOR MY BUSINESS Pin
Christian Graus14-Mar-09 8:32
protectorChristian Graus14-Mar-09 8:32 
GeneralRe: NEED 1 VB PROGRAMMER TO DEVELEP SOME SAMLL PROGRAMES FOR MY BUSINESS Pin
Dave Kreskowiak14-Mar-09 10:29
mveDave Kreskowiak14-Mar-09 10:29 
AnswerRe: NEED 1 VB PROGRAMMER TO DEVELEP SOME SAMLL PROGRAMES FOR MY BUSINESS Pin
Eddy Vluggen13-Mar-09 8:47
professionalEddy Vluggen13-Mar-09 8:47 
AnswerRe: NEED 1 VB PROGRAMMER TO DEVELEP SOME SAMLL PROGRAMES FOR MY BUSINESS Pin
0x3c013-Mar-09 9:00
0x3c013-Mar-09 9:00 
AnswerRe: NEED 1 VB PROGRAMMER TO DEVELEP SOME SAMLL PROGRAMES FOR MY BUSINESS Pin
Jon_Boy13-Mar-09 9:36
Jon_Boy13-Mar-09 9:36 
AnswerRe: NEED 1 VB PROGRAMMER TO DEVELEP SOME SAMLL PROGRAMES FOR MY BUSINESS Pin
EliottA14-Mar-09 6:04
EliottA14-Mar-09 6:04 
AnswerRe: NEED 1 VB PROGRAMMER TO DEVELEP SOME SAMLL PROGRAMES FOR MY BUSINESS Pin
Christian Graus14-Mar-09 8:34
protectorChristian Graus14-Mar-09 8:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.