Thread: dll testing

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    205

    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
    Last edited by axr0284; 03-25-2006 at 09:16 PM.

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    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'};
    Last edited by novacain; 03-26-2006 at 10:37 PM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. non-MFC DLL with MFC app question.
    By Kempelen in forum Windows Programming
    Replies: 10
    Last Post: 08-20-2008, 07:11 AM
  2. dll communicating between each other
    By cloudy in forum C++ Programming
    Replies: 5
    Last Post: 06-17-2005, 02:20 AM
  3. DLL and std::string woes!
    By Magos in forum C++ Programming
    Replies: 7
    Last Post: 09-08-2004, 12:34 PM
  4. .lib vs .h vs .dll
    By Shadow12345 in forum C++ Programming
    Replies: 13
    Last Post: 01-01-2003, 05:29 AM
  5. Passing parameters from VB to C++ through ActiveX DLL
    By torbjorn in forum Windows Programming
    Replies: 0
    Last Post: 12-10-2002, 03:13 AM