My problem is rather complicated (for me), so I'm going to post my
problem here as well as what I've done so far to solve my problem. Any
assistance would be appreciated. I originally posted this on the
C-sharp forum over at asp.net, but I'm hoping that this forum will be
more responsive. Thanks in advance for any advice/assistance you can
provide.
Hello all. I used to know some C++, but I fear I've forgotten most of
it. I need to call an unmanaged DLL, pass it some values, then one of
the byrefs of the sub returns an array. Can anyone help me call this
DLL from C# (I usually use vb.net, but I'm thinking that if I switch,
maybe it will be easier)?
This is all from the help file the other programmers made for me.
My goal is to call a C++ DLL and get back an array of information I
can stick into SQL. Effectively I'm just trying to migrate all of
their custom database format information into SQL Server so that I can
run reports off it in my intranet. They will move the databases from
their remote locations around the world back to here on a nightly
basis using remote dialup, and I will run my procedure to extract any
new data from it.
So I have to call a DLL accessdb.dll which possesses the following
function
ACCESSDB_GatewayProc(CDLL_GETREPORTDATA, (LPARAM)dwArgList,0L,0L,0L)
Here I'm not sure if the DLL has GatewayProc or ACCESSDB_GatewayProc,
as I think that when they registered the DLL in their .c file, they
probably gave it the ACCESSDB_ prefix as a means of calling that DLL's
functions? Can anyone confirm if thats how it is usually done?
This defines the first part
#define CDLL_GETREPORTDATA 0x00A1
How can I set this value in C#? Meaning, how can I declare a variable
CDLL_GETREPORTDATA and set its value to be 0x00A1?
the (LPARAM)dwArgList is an array of 9 unsigned integers
The values I need to put in the argument list are like so
//starting Date
dwArgList[1] = (Date of report)
//Ending date
dwArgList[1] = (Date of report + 86399 seconds)
Question here, I need to create an integer here that is equal to a
date in C++, I'm pretty sure its the number of seconds after 1970 or
something, but does anyone have a prefab C# function for working with
C++ dates?
now they said to set bits for each session we want to collect data
from.
dwArgList[2] = 0xFFFFFFFFUL;
dwArgList[4] = 0xFFFFFFFFUL;
dwArgList[5] |= PT_PORTABLE|PT_STATIONARY;
now here I have to use some bitwise operators, but not sure how, the
values of these two bits are combined, as I'm pretty new to C#, and
never needed to use bitwise operators in VB.NET
#define PT_PORTABLE 0x0001U
#define PT_STATIONARY 0x0002U
So after I setup this array, and pass it to the function I need to
access from the DLL, it then gives me back several pointers.
//Set up some pointers to collected data from accessdb.dll
lpstPackData = (LPERPT_PACKINFO)dwArgList[6];
lpstSessData = (LPERPT_SESSINFO)dwArgList[7];
lpstGlobData = (LPERPT_GLOBINFO)dwArgList[8];
How do I take these pointers and use them in C#?
So, I'm going to keep posting what I've done so far in the hopes that
someone either slaps me silly for doing something stupid, it works, or
someone offers some insight on how it should be done.
This is what I've done in C# so far. I honestly think this is a
testiment to the strength of the .NET languages, as this is the first
C# code I've written in my life, and so far it seems to work.
So first I set some flags.
[Flags]
enum SomeFlags
{
PT_PORTABLE = 1,
PT_STATIONARY = 2,
}
Next I created a function to convert real times over to C++ time (I
think this is referred to Julian time?)
internal static System.UInt32 convertCTimeToRealTime(System.DateTime
therealtime)
{
DateTime oldDate = DateTime.Parse("1/1/1970 0:00:00");
long realtimeticks = (therealtime.Ticks);
long olddateticks = (oldDate.Ticks);
return System.Convert.ToUInt32((realtimeticks -
olddateticks)/100000000);
}
I don't know if this is quite right, as the whole Ticks being
nanoseconds where as julian time seems to be a UInt32 value, but it
seems right after some preliminary testing. Hopefully someone can tell
me the proper way of doing this.
I created a sub that creates the paramter list described above, it
fills the lower array with values, but I don't know if it it proper
values
void setupParams()
{
System.UInt32[] ReportParams;
ReportParams = new System.UInt32[9];
ReportParams[0] = System.Convert.ToUInt32((convertCTimeToRealTime(Da teTime.Parse("1/1/1980"))))
+1;
ReportParams[1] = System.Convert.ToUInt32(convertCTimeToRealTime(Sys tem.DateTime.Now))
+86400;
ReportParams[2] = 1;
string hexString = "FFFFFFFF";
System.UInt32 UnsignedInt= Convert.ToUInt32(hexString,16);
ReportParams[3] = UnsignedInt;
ReportParams[4] = UnsignedInt;
ReportParams[5] = System.Convert.ToUInt32(SomeFlags.PT_PORTABLE) |
System.Convert.ToUInt32(SomeFlags.PT_STATIONARY);
}
So, any gurus around here that can look at my code and tell me if I'm
a bozo or if I'm on the right track? I'm starting to like C#, so I may
even continue it in the future instead of vb.net, though I'm hesitent
to go down the long road of learning a new language again after just
feeling very comfortable with vb.net
Thanks all