Groups | Blog | Home
all groups > dotnet interop > november 2006 >

dotnet interop : NetRemoteTOD DllImport



Steven Edison
11/21/2006 3:20:28 PM
In C++, what am I doing wrong here? not sure how to get the "ref" for
BufferPtr in C++, there are thousands of examples out there for C# and
VB.NET, but so few for managed C++.

[StructLayout(LayoutKind::Explicit, Size=48)]
ref class TIME_OF_DAY_INFO
{
public:
[FieldOffset(0)]
unsigned long tod_elapsedt;
[FieldOffset(4)]
unsigned long tod_msecs;
[FieldOffset(8)]
unsigned long tod_hours;
[FieldOffset(12)]
unsigned long tod_mins;
[FieldOffset(16)]
unsigned long tod_secs;
[FieldOffset(20)]
unsigned long tod_hunds;
[FieldOffset(24)]
long tod_timezone;
[FieldOffset(28)]
unsigned long tod_tinterval;
[FieldOffset(32)]
unsigned long tod_day;
[FieldOffset(36)]
unsigned long tod_month;
[FieldOffset(40)]
unsigned long tod_year;
[FieldOffset(44)]
unsigned long tod_weekday;
};

[DllImport("Netapi32.dll", CharSet=CharSet::Unicode)]
static int NetRemoteTOD(
[In][MarshalAsAttribute(UnmanagedType::LPWStr)] String^ UncServerName,
[Out] System::IntPtr^ BufferPtr
);


....
//impl:
IntPtr pBuffer;
int ret = NetRemoteTOD("\\\\MyIP", pBuffer);

TIME_OF_DAY_INFO^ Todi = (TIME_OF_DAY_INFO^)Marshal::PtrToStructure(pBuffer,
TIME_OF_DAY_INFO::typeid);
NetApiBufferFree(pBuffer); //still needed, right?

// so far ret == 0 (NERR_Success), but pBuffer == NULL..
// my guess is the "pointer to a pointer' part isn't right, needs a "ByRef"
// or "ref" type on BufferPtr, but how in managed C++? is [out] good
enough?

Thanks ahead of time.

Steven




Mattias Sjögren
11/22/2006 12:00:00 AM
Steven,

[quoted text, click to view]

With % after the type name.


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Steven Edison
11/22/2006 8:47:14 AM
Awesome. That was the whole problem, and fixed it with one tiny change.
Thanks a bunch!

Steven

[quoted text, click to view]

AddThis Social Bookmark Button