Converting managed int to unmanaged PBYTE?

  • Thread starter Thread starter Tom Glenn
  • Start date Start date
T

Tom Glenn

I have a managed method that has an int parameter that has to be passed to
an unmanaged method that takes a PBYTE and associated length as a DWORD.

Anyone have any sample code that shows how to do this?

Thanks.
 
Tom,
I have a managed method that has an int parameter that has to be passed to
an unmanaged method that takes a PBYTE and associated length as a DWORD.

Anyone have any sample code that shows how to do this?

#using <mscorlib.dll>
#include <windows.h>
#include <iostream>
using namespace System;

#pragma unmanaged
void f(LPBYTE buffer, DWORD size)
{
std::cout << "Buffer size: " << size << std::endl;
}

#pragma managed

__gc class A
{
public:
void Man(int n)
{
f( (LPBYTE)&n, sizeof(n) );
}
};

int main()
{
A* a = new A();
a->Man(12);
}
 
Thanks, how do you go in the opposite direction i.e. unmanaged to managed?
I can't seem to figure out how to take the length into account in this case.
 
Hi Tom,
Thanks, how do you go in the opposite direction i.e. unmanaged to managed?
I can't seem to figure out how to take the length into account in this
case.

Not quite sure what you're saying here... care to explain what you want to
do exactly in the opposite case?
 
Back
Top