-
dll testing
Hi,
I am having some issues with using dll. I have a program that loads home made dll at start up. The problem is that the program loads the dll correctly using loadLibrary() on the computer where I coded it but if I move it to another computer, it won't load the dll anymore. I was wondering if anybody could help test it out or help me figure it out. The file is at
http://www.rit.edu/~axr0284/testdll/testdll.zip
Forgot to add. This is the tester program:
Code:
// tester.cpp : Defines the entry point for the console application.
//
//#include "stdafx.h"
#include "windows.h"
#include <iostream>
#include <String>
#include <iomanip>
typedef int (CALLBACK* emulator_init)(int (*)(unsigned char *, int), int, unsigned char, int);
typedef int (CALLBACK* emulator_write)(unsigned char *, int);
int goodPacket(unsigned char *packet, int size);
HINSTANCE emuDLL; /*The emulator dll*/
emulator_init emuInit;
emulator_write emuWrite;
std::string error;
int main(int argc, char *argv[])
{
/*Load emulation dll*/
emuDLL = LoadLibrary("emulator"); /*Try to open the dll*/
if (emuDLL != NULL) {
error = "1) dll file emulator.dll loaded.\n";
std::cout << error;
}
else {
error = "2) Could not load dll file ";
error.append("emulator.dll");
error.append("\n");
std::cout << error;
std::cin.ignore();
std::cin.clear();
}
/*Get a pointer to the setupConnection function*/
emuWrite = (emulator_write)GetProcAddress(emuDLL,"write_data");
emuInit = (emulator_init)GetProcAddress(emuDLL,"init_Filter");
if (!emuInit){
// Free the com library
FreeLibrary(emuDLL);
error = "2) A pointer to setupConnection could not be obtained\n";
std::cout << error;
std::cin.ignore();
std::cin.clear();
exit(1);
}
else {
/*Get a pointer to the readBytes function*/
emuWrite = (emulator_write)GetProcAddress(emuDLL,"write_data");
if (!emuWrite){
// Free the com library
FreeLibrary(emuDLL);
error = "2) A pointer to readBytes could not be obtained\n";
std::cout << error;
std::cin.ignore();
std::cin.clear();
exit(1);
}
}
emuInit(&goodPacket,50,0x02,4);
unsigned char output[4] = {'2','2','2','2'};
for(int i=0;i<20;i++) {
Sleep(1000);
emuWrite(output,4);
}
std::cout << "Press any key to exit\n";
std::cin.ignore();
std::cin.clear();
// Free the emulator library
FreeLibrary(emuDLL);
return 0;
}
int goodPacket(unsigned char *packet, int size)
{
int errorCode = 0; /* This is the error code that is returned */
for(int i=0;i<size;i++) {
std::cout << std::setbase(16) << (int) packet[i];
}
std::cout << "\n";
return errorCode;
}
Thanks a lot,
Amish
-
Any particular reason you are using dynamic linking?
Static would be easier.
What other symptoms does the app show?
Does it fail to load the DLL?
or Fail to find the functions?
Or Fail to use the functions?
Are you doing any init in DLLMain and calling LoadLibrary() more than once?
Using threads and static variables and loading multiple copies of the DLL?
>>unsigned char output[4] = {'2','2','2','2'};
That won't help.....
Would cause issues in non debug versions but might be OK in a debug build.
Code:
output[5] = {'2','2','2','2'};