Closed Dll usage to control a module

Hi there,
I'm having trouble using a dll that was made to control a module. The producer just sent me some dll's (that I'm not able to know their implementation) and two header files. I am supposed to access the class declared inside this specific dll and use its methods just with the header.
I was told by the vendor that the dll was developed in VC++6.0 (if that makes any difference). The header file is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// UsbOtdrAPI.h: interface for the UsbOtdrAPI class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_USBOTDRAPI_H__34C59198_66E1_4A1D_93AA_CFD402024F67__INCLUDED_)
#define AFX_USBOTDRAPI_H__34C59198_66E1_4A1D_93AA_CFD402024F67__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class __declspec(dllexport) UsbOtdrAPI  
{
private:
	void cleanUp();

private:
	// scan parameters
	//int scanMode;			// 0=Realtime scan, 1=Averaging scan
	//int scanRange;		// 6, 14, 30, 60, 120, 240 km
	//int avgSeconds;		// average time for averaging scan, 6 - 600 seconds
	//int waveLength;		// 1310, 1490, 1550, 1625 nm
	//int pulseWidth;		// 10, 30, 100, 300, 1000, 3000, 10000, 20000 ns
	//double IOR;			// index of refraction, default 1.4700

	// scanning result
	//int points;			// number of trace points
	//double *pixels;		// trace data, in dB

	// Event detection parameters
	//int sensitivity;		// low, medium, high
public:
	// attribute accessing functions
	int setScanMode(int sm = 0);	// default real-time scan, return 0=success
	int getScanMode();				// return -1=failed
	int setScanRange(int sr = 6);	// default 0=6 km, return 0=success
	int getScanRange();				// return -1=failed
	int setAvgSeconds(int as = 30);	// default 30 seconds, return 0=success
	int getAvgSeconds();			// return -1=failed
	int getRemainingSeconds();		// return -1=failed
	int setWaveLength(int wl = 1310);	// default 1310nm, return 0=success
	int getWaveLength();			// return -1=failed
	int setPulseWidth(int pw = 10); // default 10ns, return 0=success
	int getPulseWidth();			// return -1=failed
	int setIOR(double i = 1.47l);	// default=1.47, return 0=success
	double getIOR();				// return 0.0=failed
	int setSensitivity(int s = 0);	// default=0(low), 1=medium, 2=high
	int getSensitivity();			// return -1=failed

	// scanning result
	int getNumberOfPixels();	// return the number of data points
	int getPixels(double *pix);	// user must supply the allocated memory buffer
	double kmperpixel();		// distance per pixel, unit: km

	int getNumberOfEvents();	// return the number of detected events
	int getEvents(void *buf);	// copy the event table into caller provided buffer
public:
	// API functions
	virtual void Initilization();// all attributes accessible/legal after this
	virtual void startScan();	// lpfn is used to notify scan status
	virtual void stopScan();	// kill scanning process before it completes
	virtual void Close();		// all attributes invalid after this

// SOR file function
public:
	virtual void opensor(char *filename);
	virtual void savesor(char *filename);

	// status
private:
	int error;				// last status
	char *errmsg;			// if error is true, this is the reason
	void eventDetection();	// build event table

public:	
	void setErrmsg(char *str);
	void setErrNo(int err);
	int getError();				// return -1=failed, 0 = success, others with errmsg
	int getErrMsg(char *buf);	// return -1=failed.

public:
	// default constructor and destructor
	UsbOtdrAPI();
	~UsbOtdrAPI();

private:
	bool knowSplitter;	// enable splitter detection

};

#endif // !defined(AFX_USBOTDRAPI_H__34C59198_66E1_4A1D_93AA_CFD402024F67__INCLUDED_)


I tried generating a main file that would just include the header and try to instantiate the class and use it's methods, but I'm not even succeeding compiling the file. I created a main.cpp as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include "UsbOtdrAPI.h"

using namespace std;

int main(){
	UsbOtdrAPI *usbotdr;
	usbotdr = new UsbOtdrAPI();
	usbotdr->Initilization();

        int sm = 8;
	int ret; // integer for status return, error checking omitted
	ret = usbotdr->setScanMode(sm);
	cout << ret;
	return 0;
}


Right now, I'm using MinGw to compile the code, but I can try different compilers if it's said so. What I get from the compiler is:

C:\test>g++ -o run.exe main.cpp
C:\Users\PEDRO~1.CAR\AppData\Local\Temp\cckybr5F.o:main.cpp:(.text+0x24): undefined reference to `UsbOtdrAPI::UsbOtdrAPI()'
C:\Users\PEDRO~1.CAR\AppData\Local\Temp\cckybr5F.o:main.cpp:(.text+0x55): undefined reference to `UsbOtdrAPI::setScanMode(int)'
collect2: ld returned 1 exit status


Thanks everyone for your time. I'll be waiting for a response.

--
Pedro

Did they only send *.h files and *.dll files.
Did they not send a *.lib file??

P.S - as they say it was witten in MFC6 - you really have your work cut out trying to
use GCC to create a program to link to it.

Last edited on
I am not sharp on the topic, but look at this:
http://www.mybestnotes.co.in/dll/what-is-the-utility-of-the-keyword-dllimport-dllexport.php

According to it, you will need a .lib file from the vendor, use it when linking, and change
 
class __declspec(dllexport) UsbOtdrAPI
to
 
class __declspec(dllimport) UsbOtdrAPI


Regards
Appreciate your responses.

guestgulkan:
Did they not send a *.lib file??

Yes, you are right. They did.

Here is what I did now:
guestgulkan:
..as they say it was witten in MFC6 - you really have your work cut out trying to
use GCC to create a program to link to it.

So, I created a Win32 Console application in MFC6, imported all the files they sent me to the workspace and tried using the same main that I showed in the previous message.
I also tried using simeonz recommendation: I've changed dllexport to dllimport and here is what I got from MFC6:

Linking...
test3.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: int __thiscall UsbOtdrAPI::setScanMode(int)" (__imp_?setScanMode@UsbOtdrAPI@@QAEHH@Z)
test3.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall UsbOtdrAPI::UsbOtdrAPI(void)" (__imp_??0UsbOtdrAPI@@QAE@XZ)
Debug/test3.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

I tried the same using GCC compiler, just in case, and my compiler output was:
C:\Users\PEDRO~1.CAR\AppData\Local\Temp\cczkauKD.o:main.cpp:(.text+0x24): undefined reference to `_imp___ZN10UsbOtdrAPIC1Ev'
C:\Users\PEDRO~1.CAR\AppData\Local\Temp\cczkauKD.o:main.cpp:(.text+0x4f): undefined reference to `_imp___ZN10UsbOtdrAPI11getScanModeEv'
collect2: ld returned 1 exit status


I can't see if I am too far from what I need. I would much appreciate if you guys could tell me something more.
Thanks again and best regards.
You need to tell the linker to use the .lib file. I know this was configurable through project settings in the VS6 IDE.
Got it. Just made it work adding the .lib file there.
I'm also trying to use the Visual C++ 2005, which I have a student license . Do you know where do I add the .lib file there?
Thank you for you help. It was really useful.

Regards
Just found it;
Project>"Project Name" Properties
In the lateral tab: Configuration Properties>Linker>Input and added the .lib file there in the "Additional Dependencies".
Topic archived. No new replies allowed.