Click here to Skip to main content
15,892,965 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionOutlook Object Model Pin
Mahesh Kulkarni28-Jun-06 20:40
Mahesh Kulkarni28-Jun-06 20:40 
AnswerRe: Outlook Object Model Pin
HakunaMatada28-Jun-06 20:56
HakunaMatada28-Jun-06 20:56 
GeneralRe: Outlook Object Model Pin
Mahesh Kulkarni28-Jun-06 21:01
Mahesh Kulkarni28-Jun-06 21:01 
GeneralRe: Outlook Object Model Pin
HakunaMatada28-Jun-06 21:13
HakunaMatada28-Jun-06 21:13 
GeneralRe: Outlook Object Model Pin
Mahesh Kulkarni29-Jun-06 1:34
Mahesh Kulkarni29-Jun-06 1:34 
GeneralRe: Outlook Object Model Pin
HakunaMatada29-Jun-06 17:38
HakunaMatada29-Jun-06 17:38 
QuestionHow to synchronization audio and video in a mpeg2ps file? Pin
chenxiujie28-Jun-06 20:21
chenxiujie28-Jun-06 20:21 
Questionloading DLL library Pin
sach!!28-Jun-06 20:20
sach!!28-Jun-06 20:20 
hi !

I am facing a problem loading a DLL file in client application. I am using a LoadLibrary() function to load a dll file. The problem is that ; load library does not return NULL. I cheked this using value of the handle its returning. But getLastError gives error code 6 :: "Invalid Handle".

I checked the path several times. There is no problem in path for sure.

I dont know where i am goin wrong??

Plz help me out.

I am posting my code here

NewDll.cpp (win32 DLL project)
// NewDll.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"

HINSTANCE gl_hModule = NULL;

BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
					 )
{
    switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
			{
				gl_hModule = (HINSTANCE)hModule;
				break;	
			}
	case DLL_PROCESS_DETACH:
			break;
	case DLL_THREAD_ATTACH:
			break;
	case DLL_THREAD_DETACH:
			break;

	return TRUE;
	}
}

void getString(HINSTANCE hInst)
{
	char load_str[80];
	LoadString(hInst,1,load_str,80);
	MessageBox(NULL,load_str,"STring Retrieved",NULL);
}


TestDllDlg.cpp( Client app , I am loadin dll in OnOK() function just to test)
[code] // TestDllDlg.cpp : implementation file
//

#include "stdafx.h"
#include "TestDll.h"
#include "TestDllDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

typedef void (*MYAPP)(HINSTANCE);  // pointer to: void function(HINSTANCE)

MYAPP gets1=NULL;
 
HINSTANCE ghInst =NULL;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestDllDlg dialog

CTestDllDlg::CTestDllDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTestDllDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTestDllDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CTestDllDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTestDllDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTestDllDlg, CDialog)
	//{{AFX_MSG_MAP(CTestDllDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestDllDlg message handlers

BOOL CTestDllDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CTestDllDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CTestDllDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CTestDllDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CTestDllDlg::OnOK() 
{
	// TODO: Add extra validation here
              
  HMODULE hMod ;        // handle to loaded library module
  BOOL    bRes;        // BOOL to check if DLL was successfully unloaded 
  
  // returns a handle to the DLL, otherwise NULL
  ghInst= LoadLibrary("F:\\MyProjects2\\NewDll\\Debug\\NewDll.dll");
	
  if(ghInst==NULL)
  {
		MessageBox("CANT LOAD THE LIBRARY","ER0ROR",NULL);
  }

  // returns the address of the DLL functions, otherwise NULL
  gets1 = (MYAPP) GetProcAddress(ghInst,"getString");
 
  // (DLL function address) (function parameters)
  HINSTANCE tempInst=GetModuleHandle(NULL);

  (*gets1)(tempInst);
 
   
  // returns nonzero if sucussful 
  bRes = FreeLibrary(hMod); 
	

	CDialog::OnOK();
}

AnswerRe: loading DLL library Pin
Cedric Moonen28-Jun-06 20:23
Cedric Moonen28-Jun-06 20:23 
GeneralRe: loading DLL library Pin
sach!!28-Jun-06 21:10
sach!!28-Jun-06 21:10 
AnswerRe: loading DLL library Pin
Laxman Auti28-Jun-06 21:24
Laxman Auti28-Jun-06 21:24 
GeneralRe: loading DLL library Pin
Cedric Moonen28-Jun-06 21:31
Cedric Moonen28-Jun-06 21:31 
AnswerRe: loading DLL library Pin
Hamid_RT28-Jun-06 20:45
Hamid_RT28-Jun-06 20:45 
AnswerRe: loading DLL library Pin
Stephen Hewitt28-Jun-06 20:49
Stephen Hewitt28-Jun-06 20:49 
GeneralRe: loading DLL library Pin
Rajesh R Subramanian28-Jun-06 21:01
professionalRajesh R Subramanian28-Jun-06 21:01 
GeneralRe: loading DLL library Pin
Stephen Hewitt28-Jun-06 21:04
Stephen Hewitt28-Jun-06 21:04 
GeneralRe: loading DLL library Pin
sach!!28-Jun-06 21:28
sach!!28-Jun-06 21:28 
GeneralRe: loading DLL library Pin
Stephen Hewitt28-Jun-06 21:35
Stephen Hewitt28-Jun-06 21:35 
GeneralRe: loading DLL library Pin
sach!!28-Jun-06 23:08
sach!!28-Jun-06 23:08 
QuestionRe: loading DLL library Pin
David Crow29-Jun-06 3:12
David Crow29-Jun-06 3:12 
QuestionCombo Scrollbar Pin
Sarath C28-Jun-06 19:38
Sarath C28-Jun-06 19:38 
AnswerRe: Combo Scrollbar Pin
Hamid_RT28-Jun-06 20:04
Hamid_RT28-Jun-06 20:04 
Questionhi all [modified] Pin
ashish dogra28-Jun-06 19:33
ashish dogra28-Jun-06 19:33 
AnswerRe: hi all Pin
Hamid_RT28-Jun-06 19:36
Hamid_RT28-Jun-06 19:36 
GeneralRe: hi all Pin
ashish dogra28-Jun-06 19:41
ashish dogra28-Jun-06 19:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.