CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2008
    Posts
    2

    Wrapper combining two dlls into one

    Application Overview:

    I am communicating with two identical cameras connected via Ethernet / IP.
    The driver for each camera is provided as a dll.
    Application programming language is LabVIEW. (LabVIEW can easily communicate with dlls using a "Called Shared Library" function).

    My Approach:

    To work with the two cameras at the same time it is required to create a new wrapper dll that calls the two driver dll's. I copied and uniquely named the driver dll. I then used the LoadLibrary function and the GetProcAddress to explicitly load each dll in my wrapper dll.

    My Problem:

    Each time I call a dll function in my wrapper dll, I need to create the objects. In other words, I am losing the handle to my objects. I need help on how to properly instantiate the objects and / or pointer to the objects. My wrapper dll is operational, but as mentioned within each function I presently need to recreate each object.

    Here is some sample code from the wrapper dll to hopefully clarify:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include "stdafx.h"
    #include <conio.h> //for getch
    #include "Multiple.h"
    
    
    
    
    extern "C"
    {
    __declspec(dllexport) int wrpReadMeasurement(TMeasurement *Measurement1, TMeasurement *Measurement2)
    	{
    		CFifoWrapper Fifo1(1);
    		CFifoWrapper Fifo2(2);
    		Fifo1.pfn_FifoIpInit(0x01020304, 0x01020309, 10000);
    		Fifo2.pfn_FifoIpInit(0x01020305, 0x01020309, 10000);
    
    		Fifo1.pfn_FifoReadMeasurement(Measurement1);
    		Fifo2.pfn_FifoReadMeasurement(Measurement2);
    		return 0;
    	}
    
    		__declspec(dllexport) int wrpGetHeadSNSingle(void)
    	{
    		CFifoWrapper Fifo1(1);
    		Fifo1.pfn_FifoIpInit(0x01020304, 0x01020309, 10000);
    		return Fifo1.pfn_FifoGetHeadSN();		
    	}
    }
    In the second function I want to avoid the lines:
    Code:
    CFifoWrapper Fifo1(1);
    Fifo1.pfn_FifoIpInit(0x01020304, 0x01020309, 10000);
    The code snippet below shows the section of header that loads each dll.

    Code:
    // constructor
    CFifoWrapper::CFifoWrapper(int iInstanceNumber)
    {
    
    	bComplete = false; // bComplete indicates that the constructor did not complete successfully
    	
    	// load the dll
    	if (iInstanceNumber == 1)
    		hFifoHandle = LoadLibrary(_T("fifo1.dll"));
    	else
    		hFifoHandle = LoadLibrary(_T("fifo2.dll"));
    
    	
    	if (hFifoHandle == NULL) // check error status
    		return; // return with bComplete = false, to indicate error status
    Thank you in advance for your time and I will gladly provide more details if required.

  2. #2
    Join Date
    Mar 2008
    Posts
    2

    Re: Wrapper combining two dlls into one

    Just bumping my post. Any help appreciated.

    Thank you, Steve.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured