Is there a simpler way?

F

Fred Hebert

Tim,

You are right I just got used to the common library in all of the
different Borland products and GNU compiler we are using. I have already
recreated most of the "missing" stuff. My blood pressure is starting to
come down and I am feeling a little better already. :)

Anyhow, you sound like you are fairly sharp. I have a problem with this
program I am converting. Of the thousands of lines of code I have one
problem that I thought would be simple, but is giving me fits.

I am trying to use a Win32 DLL in a .NET application. The DLL
encapsulates the interface to some external hardware and has many
exported functions, but I am having problems with only 1. The function
requires the handle of a windows form and I can't seem to get it to work.

I created the simplest project I could to demonstrate the problem if you
can spend 5 minutes cutting pasting I would greatly appreciate it:

1. Create a new VC.NET Windows Forms Application.

2. Drop 4 TextBox controls and a Button on the form.
[textBox1]
[textBox2]
[textBox3]
[textBox4]
[button1]

3. Edit the properties of the text controls like this:
[textBox1]
Name: IpEdit
Text: 10.1.1.1
[textBox2]
Name: PortEdit
Text: 1234
[textBox3]
Name: TimeoutEdit
Text: 10
[textBox4]
Name: KeyEdit
Text: fffffffffffffffffffffffffffffff << should be 32 f's

4. Double Click on the button, and enter the following code:
---------------------------------------
unsigned char BinKey[16]; // key is entered in HEX but
must be converted to binary value for use
for(int i=0; i < KeyEdit->Text->Length; i=i+2)
{
BinKey[i>>1] = (unsigned int)(hextobin(KeyEdit->
Text->get_Chars(i)) << 4) +
hextobin(KeyEdit->Text->get_Chars(i+1));
}
OmniConnect(IpEdit->Text,
PortEdit->Text->ToInt32,
TimeoutEdit->Text->ToInt32,
BinKey,
Handle);
---------------------------------------

5. The the beginning of the Form1.h, just after the "#pragma once" line
add the following lines:
---------------------------------------
#include <windows.h>
#define hextobin(c) ((c)>='a'&&(c)<='f' ? (c)-'a'+10 : (c)>='A'&&(c)
<='F' ? (c)-'A'+10 : (c)-'0')
// define function types for the exported functions in the DLL
typedef int (_stdcall *pOmniConnect) (char * IpAddress,
unsigned int Port,
unsigned int Timeout,
unsigned char EncryptionKey[16],
HWND NotifyWindow);
// declare function variables for the exported functions in the DLL
pOmniConnect OmniConnect;
---------------------------------------

Now I know I left out the OnCreate of the form where the DLL is loaded
and all of the other DLL exports, but I think I have everything you need
to compile, that is once the "Handle" issue is resolved.

Of course it won't run but right now I am just trying to get past this
one problem. In the real program, if I comment out the code in the
button click the rest of the program runs fine. I didn't have problems
with any of the functions, but most of them just pass strings and
integers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top