Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / May 2004

Tip: Looking for answers? Try searching our database.

Converting managed int to unmanaged PBYTE?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tom Glenn - 27 May 2004 01:38 GMT
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.
Tomas Restrepo \(MVP\) - 27 May 2004 03:46 GMT
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);
}
Tom Glenn - 27 May 2004 18:50 GMT
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.

> Tom,
>
[quoted text clipped - 30 lines]
>    a->Man(12);
> }
Tomas Restrepo \(MVP\) - 28 May 2004 00:43 GMT
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?

Signature

Tomas Restrepo
tomasr@mvps.org


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.