473,385 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Assistance please with calling an outside C++ DLL?

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
Nov 15 '05 #1
0 1252

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: CHRIS ALOZIE | last post by:
NIGERIAN TELECOMMUNICATION LIMITED. FEDERAL SECRETARIAT COMPLEX, GARKI, ZONE II ABUJA. E-MAIL: chrisalozie@uboot.com DATE:16th August 2003 REF:rf/ntl-fgn
1
by: Pujo Aji | last post by:
I have a problem with an object calling outside method: Forexample in the main part I have an object and the object will do something time independent, and after it is finished working it should ...
0
by: Joe Ross | last post by:
(Apologies in advance if there is a better forum for asking advice on this topic). Our ASP.NET application occasionally starts spitting out OutOfMemory exceptions. When this happens, the memory...
5
by: chump1708 | last post by:
line 50 - char *b, q, *r; line 200 - b = getbuf (); Line 201 q = *b; Line 212 R = anotherfunction (b); Lines 213-2003 /* we want to use 'q' and 'r' here */
5
by: Ben | last post by:
This is a follow-on from the "Help with array/pointer segmentation fault needed" thread.. I have not been able to find much information on the rules for macros. I want to be able to call a macro...
0
by: VincentJS | last post by:
Greetings fellow programmers! Could someone explain to me HOW to call a mousehook OUTSIDE the calling thread (or program). Microsoft says following: HHOOK SetWindowsHookEx( int...
22
by: Amali | last post by:
I'm newdie in c programming. this is my first project in programming. I have to write a program for a airline reservation. this is what i have done yet. but when it runs it shows the number of...
3
by: gaurav92K | last post by:
sir i am working in a company . there are many pc. i want to use remote assistance. i configure all group policy which are related remote assistance.and i enable service through remote in system...
0
by: UWALAKA | last post by:
> FROM THE DESK OF DIRECTOR GENERAL F.M.A LAGOS EMAIL, dranthfiles1@indiatimes.com Good Day, I Dr.ANTHONY UWALAKA presently I am the director general of finance in the federal ministry of...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.