Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DLL HeLL...

Status
Not open for further replies.

CubeE101

Programmer
Nov 19, 2002
1,492
US
I am trying to access an API for an eMatrix PDM through a DLL... (mqlio32.dll or mqlvb32.dll)

mqlio32.dll is intended for C++
mqlvb32.dll is intended for (you guessed it) VB

the documentation shows the declarations for a few of the functions as follows:
Code:
int mqlOpen(void);
int mqlExecute(MQLBOS_STR_FAR_PTR format);
int mqlOpenLog(char * filename);
int mqlCloseLog(void);
int mqlTimeout(int seconds);
int mqlPending(void);
int mqlErrors(void);
int mqlOutputs(void);
int mqlInput(char * buffer, int size);
int mqlOutput(char * buffer, int limit);
int mqlError(char * buffer, int limit);
int mqlClose(void);

To get these to work in VB(6) they were declared like this...
Code:
Declare Function mqlOpen Lib "mqlvb32.dll" () As Integer
Declare Function mqlExecute Lib "mqlvb32.dll" (ByVal mqlcmd$) As Integer
Declare Function mqlOpenLog Lib "mqlvb32.dll" (ByVal FileName$) As Integer
Declare Function mqlCloseLog Lib "mqlvb32.dll" () As Integer
Declare Function mqlTimeOut Lib "mqlvb32.dll" (ByVal Seconds%) As Integer
Declare Function mqlPending Lib "mqlvb32.dll" () As Integer
Declare Function mqlErrors Lib "mqlvb32.dll" () As Integer
Declare Function mqlOutputs Lib "mqlvb32.dll" () As Integer
Declare Function mqlInput Lib "mqlvb32.dll" (ByVal Buffer$, ByVal Size%) As Integer
Declare Function mqlOutput Lib "mqlvb32.dll" (ByVal Buffer$, ByVal Limit%) As Integer
Declare Function mqlError Lib "mqlvb32.dll" (ByVal Buffer$, ByVal Limit%) As Integer
Declare Function mqlClose Lib "mqlvb32.dll" () As Integer

So far in C#, I currently have this...
Code:
        [DllImport("mqlio32.dll")]
        private static extern int mqlOpen();
        [DllImport("mqlio32.dll")]
        private static extern int mqlExecute(String mqlcmd);
        [DllImport("mqlio32.dll")]
        private static extern int mqlOpenLog(String FileName);
        [DllImport("mqlio32.dll")]
        private static extern int mqlCloseLog();
        [DllImport("mqlio32.dll")]
        private static extern int mqlTimeout(int Seconds);
        [DllImport("mqlio32.dll")]
        private static extern int mqlPending();
        [DllImport("mqlio32.dll")]
        private static extern int mqlErrors();
        [DllImport("mqlio32.dll")]
        private static extern int mqlOutputs();
        [DllImport("mqlio32.dll")]
        private static extern int mqlInput(String Buffer, int Size);
        [DllImport("mqlio32.dll")]
        private static extern int mqlOutput(String Buffer, int Limit);
        [DllImport("mqlio32.dll")]
        private static extern int mqlError(String Buffer, int Limit);
        [DllImport("mqlio32.dll")]
        private static extern int mqlClose();

I tried changing the Sting's to char *, but that is unsafe...
So I tried it in an unsafe block, and it still does not work...

Now, part of the DLL does work in C#...

I can open up the interface window with mqlOpen
I can send a command to the interface with mqlInput, which does show up in the interface window.
And then I can recieve whether or not any output is pending with mqlPending
BUT... I can not retrieve the output with mqlOutput...

It returns how many characters were in the Output, but it returns the unmodified buffer string that you passed it... (which consist of about 5000 blank spaces which worked fine in VB and was instructed in the docs...)

Does anyone see anything imediately wrong with my declarations?

if you need more info, please ask... this is driving me crazy...

Have Fun, Be Young... Code BASIC
-Josh

cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Try one of the the followings:
1. Maybe you should have to call mqlOutputs() before ?
2.
Code:
[DllImport("mqlio32.dll")]
private static extern int mqlOutput(ref string Buffer, int Limit);
3.
Code:
[DllImport("mqlio32.dll"),CharSet=System.Runtime.InteropServices.CharSet.Auto)]
private static extern int mqlOutput(ref string Buffer, int Limit);

obislavu

 
1.)... I don't think it needs to be called first, we never had to before...
MQLDocumentation said:
Function mqlOutputs

Synopsis int mqlOutputs (void);

Description This function maintains a counter of the number of times the user-supplied outputCallback routine has been called, by recording the number of outputs from mqlCallback.

Returns The number of times that mqlCallback called the outputCallback routine.

Note The counter is reset each time mqlCallback is called.

2.) I tried using:
Code:
[DllImport("mqlio32.dll")]
private static extern int mqlOutput(ref string Buffer, int Limit);
...
tstVal = mqlOutput(ref buffer, Limit);

and

Code:
[DllImport("mqlio32.dll")]
private static extern int mqlOutput(out string Buffer, int Limit);
...
tstVal = mqlOutput(out buffer, Limit);

The program crashes once it gets to this point though... no error messages...

3.) Same happens here... I did have to change the code to remove a ")" to get it to compile...
Code:
[DllImport("mqlio32.dll"[b][COLOR=red])[/color][/b],CharSet=System.Runtime.InteropServices.CharSet.Auto)]
private static extern int mqlOutput(ref string Buffer, int Limit);

Sooo... I guess no luck so far :-(

Am I calling something the wrong way?

Do you have any other ideas?

here is the listing for mqlOutput:
MQLDocumentation said:
Function mqlOutput

Synopsis int mqlOutput(char * buffer, int limit);

Description This function is used by mqlCallback to receive data from MQL or the Collaboration Server.
char * buffer is a pointer to the output buffer.
int limit is the buffer size limit.

Returns The size of the buffer received or MQLERROR on failure.

Thanks for your help so far though...

Have Fun, Be Young... Code BASIC
-Josh

cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
ok... what is the difference in C# and VB.Net as far as libraries go???

I got it to work fine with VB.Net...

The C# version still is not working though...

I thought they were supposed to use the same CLI and JIT compiler...

Is it the way that I am referencing the external Libs???

Here are the working VB.Net declarations:
Code:
    Public Declare Function mqlOpen Lib "mqlVB32.dll" () As Integer
    Public Declare Function mqlPending Lib "mqlVB32.dll" () As Integer
    Public Declare Function mqlInput Lib "mqlVB32.dll" (ByVal Buffer$, ByVal Size%) As Integer
    Public Declare Function mqlOutput Lib "mqlVB32.dll" (ByVal Buffer$, ByVal Limit%) As Integer
    Public Declare Function mqlError Lib "mqlVB32.dll" (ByVal Buffer$, ByVal Limit%) As Integer
    Public Declare Function mqlClose Lib "mqlVB32.dll" () As Integer

Have Fun, Be Young... Code BASIC
-Josh

cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top