M
Mike
Folks, I got this to works, but in a kludgy way. I am wondering if I
be more precise and direct with the cli:
The unmanaged (RPC) function is:
BOOL APIENTRY FileSearch(const char *s,
DWORD &n,
unsigned __int64 *&p);
I'm wrapping it in a C++/CLR "proxy" library with this:
static array<UInt64^>^ FileSearch(String^ s)
{
const char* psz = (const char*)(void*)Marshal::StringToHGlobalAnsi(s);
array<UInt64^>^ alist = {};
UInt64 *p = NULL;
DWORD count = 0;
if :FileSearch(psz, count, p)) {
alist = gcnew array<UInt64^>(count);
for (DWORD i=0; i < count; i++) {
alist = p;
}
if (p) {
//************ TODO: caused fault. ***********
// Need to expose the rpc client released function
//::free(p);
//************ TODO: caused fault. ***********
}
}
Marshal::FreeHGlobal(IntPtr((void*)psz));
return alist;
}
In a VB.NET client, oddly, the managed signature returns as a
System.ValueType. So I painly figured out how to work with that with a
bitconverter function:
Dim data() As ValueType = FileSearch("MP3")
For Each v As ValueType In data
Dim fr As TSearchRecord = ToSearchRecord(v)
Console.WriteLine(" - area: {0} ref: {1}", fr.Area, fr.Ref)
Next
// VB.NET doesn't have a HIWORD/LOWORD concept?
Function ToSearchRecord(ByVal i64 As Long) As TSearchRecord
Dim b As Byte() = BitConverter.GetBytes(i64)
Dim rec As TSearchRecord
rec.Ref = BitConverter.ToUInt32(b, 0)
rec.Area = BitConverter.ToUInt32(b, 4)
Return rec
End Function
I guess the array<UInt64^>^ is not quite cli compliant. Correct?
Is there a more straight forward way?
Ideally, an int64 item is:
typedef struct tagTSearchRecord {
DWORD ref;
DWORD area;
} TSearchRecord;
So I tried to return this:
static array<TSearchRecord^>^ FileSearch(String^ s)
but the compiler did not like this. I think TSearchRecord needs to be
a managed class, but I don't know if I want this overhead allocated
per item.
Any tip, guidance? It would be greatly appreciated.
Thanks
--
be more precise and direct with the cli:
The unmanaged (RPC) function is:
BOOL APIENTRY FileSearch(const char *s,
DWORD &n,
unsigned __int64 *&p);
I'm wrapping it in a C++/CLR "proxy" library with this:
static array<UInt64^>^ FileSearch(String^ s)
{
const char* psz = (const char*)(void*)Marshal::StringToHGlobalAnsi(s);
array<UInt64^>^ alist = {};
UInt64 *p = NULL;
DWORD count = 0;
if :FileSearch(psz, count, p)) {
alist = gcnew array<UInt64^>(count);
for (DWORD i=0; i < count; i++) {
alist = p;
}
if (p) {
//************ TODO: caused fault. ***********
// Need to expose the rpc client released function
//::free(p);
//************ TODO: caused fault. ***********
}
}
Marshal::FreeHGlobal(IntPtr((void*)psz));
return alist;
}
In a VB.NET client, oddly, the managed signature returns as a
System.ValueType. So I painly figured out how to work with that with a
bitconverter function:
Dim data() As ValueType = FileSearch("MP3")
For Each v As ValueType In data
Dim fr As TSearchRecord = ToSearchRecord(v)
Console.WriteLine(" - area: {0} ref: {1}", fr.Area, fr.Ref)
Next
// VB.NET doesn't have a HIWORD/LOWORD concept?
Function ToSearchRecord(ByVal i64 As Long) As TSearchRecord
Dim b As Byte() = BitConverter.GetBytes(i64)
Dim rec As TSearchRecord
rec.Ref = BitConverter.ToUInt32(b, 0)
rec.Area = BitConverter.ToUInt32(b, 4)
Return rec
End Function
I guess the array<UInt64^>^ is not quite cli compliant. Correct?
Is there a more straight forward way?
Ideally, an int64 item is:
typedef struct tagTSearchRecord {
DWORD ref;
DWORD area;
} TSearchRecord;
So I tried to return this:
static array<TSearchRecord^>^ FileSearch(String^ s)
but the compiler did not like this. I think TSearchRecord needs to be
a managed class, but I don't know if I want this overhead allocated
per item.
Any tip, guidance? It would be greatly appreciated.
Thanks
--