473,385 Members | 1,409 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.

Help with calling external DLL....

Hey all,

Just starting to play with calling DLL's outside the .NET sandbox and
I'm hoping for some help with the following:

The function prototypes:

[DllImport("GM6S32.Dll")]
public static extern long GMW_DS_Query(
[MarshalAsUnmanagedType.LPStr)] string szSQL,
[MarshalAs(UnmanagedType.LPStr)] string szFilter,
[MarshalAs(UnmanagedType.LPStr)] string szFDlm,
[MarshalAs(UnmanagedType.LPStr)] string szRDlm );

[DllImport("GM6S32.Dll")]
public static extern long GMW_DS_Fetch(
long iHandle,
[MarshalAs(UnmanagedType.LPStr)] string szBuf,
int iBufSize,
int nGetRecs );
The code I'm calling them with:

long queryret;
long fetchret;
string qryretstring="";
queryret=GMAPISupport.GMW_DS_Query(qrystring,"","0 ","0");
fetchret= GMAPISupport.GMW_DS_Fetch(queryret,qryretstring,32 767,1);
GMAPISupport.GMW_DS_Close( queryret );
The problem is with the GMW_DS_Fetch call, it is returning a null
reference exception for some reason. The params are:

GMW_DS_Fetch( <iHandle>, <szBuf>, <iBufSize>, <nGetRecs> )

Parameters:
<iHandle> The Datastream handle returned by GMW_DS_Query
<szBuf> Buffer to hold result packet
<iBufSize> Size of returned <szBuf>
<nGetRecs> Number of records to fetch.

So, the szBuf param is really an empty string that I'm passing ByRef so
the DLL has somewhere to dump its data. The general Idea is to run the
call twice, once to get the return data params (the size of the return
set, number of records, etc.,) again to get the data. Here, I'm just
using the max possible values and trying to return a single record to
keep it simple but, as I said earlier, I'm getting a null reference
exception.

Here's the manufacturer's code example in C++ (SQL Query shortened for
clarity):

long iHandle = 0;
long iOK = 0;

char *szSQL1 = "SELECT .... FROM....WHERE"
// send DataStream SQL Query
if((iHandle = GMW_DS_Query(szSQL1)) > 0 )
{
// allocate buffer for 200 contacts at 40 chars per/name
long iBufSize = 200*40 +20;
char *szBuf = new char[iBufSize];

// fetch first 200 records into buffer
iOK = GMW_DS_Fetch( iHandle, szBuf, iBufSize, 200 );

// do whatever with the data
ODS( szBuf );

// make sure to delete the buffer
delete [] szBuf; szBuf = NULL;

// close the query
iOK = GMW_DS_Close( iHandle ); iHandle = 0;
}

Any ideas?

-r

Nov 16 '05 #1
1 4646
[DllImport("GM6S32.Dll")]
public static extern long GMW_DS_Fetch(
long iHandle,
[MarshalAs(UnmanagedType.LPStr)] string szBuf,
int iBufSize,
int nGetRecs );


You should use StringBuilder instead of string for output string
buffers.

iHandle should most likely be of type int instead of long.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #2

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

Similar topics

2
by: Mike | last post by:
We have a large c++ program that runs under Windows NT Embedded to control an instrument. That program has been written to run external python scripts. The computer where this code runs does not...
3
by: Carlo Chung | last post by:
Hi, I have a question about how to retrieve the information of the calling instance, such as instance name, in an external C procedure. Thank you, Carlo Chung
8
by: Johnny Knoxville | last post by:
I've added a favicon to my site (http://lazyape.filetap.com/) which works fine if you add the site to favourites the normal way, but I have some JavaScript code on a couple of pages with a link,...
17
by: VM | last post by:
In my Windows app, I'm running a batch process that's composed of a FOR loop that'll run 15,000 times (datatable row count), copy cthe data of each row -3 fields- to a struct, and send the strct to...
2
by: | last post by:
Help! I'm new to c++, and am breaking my teeth on MS Visual C++ (bundled within Visual Studio .NET 2003). Am trying to link simple c++ code to fortran dlls created in Compaq Visual Fortran (v6.1)....
2
by: jhhbr549 | last post by:
I need my result to print out only in the box created with a scroll bar. It has to look like this. The Twelve Days of It by John H. Howard On the First day of It My true LOVE of Computers...
22
by: SQACSharp | last post by:
I'm trying to get the control name of an editbox in another window. The following code set the value "MyPassword" in the password EditBox but it fail to return the control name of the EditBox. ...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
3
by: John Smith | last post by:
Hi All, I have a script which reads a data file, reads the characters one by one and if a certain character is meet it does something else, at the moment it echos the fact that it meet a certain...
5
by: althafexcel | last post by:
hi everyone Im trying to include an external js in my aspx page under the head tag, it doesn't load or it displays an object expected error whenver the function from the .js is called. Actually...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.