Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an mfc dll, it was an mfc console application which I want to add the code as dll to a clr c++ aoo.
code of console :
C++
#include <windows.h>
#include <iostream>
#include <complex>

void main()
{
    double i,c,d,f,g,e;
	HDC hdc = GetDC(GetDesktopWindow());
    DWORD ret = GetDeviceCaps(hdc, HORZSIZE);
    DWORD ret2 = GetDeviceCaps(hdc, VERTSIZE);
    std::cout << "Your screen size in inches is " << ret/25.4 << "\" x " << ret2/25.4 << "\" \n";
    ReleaseDC(GetDesktopWindow(), hdc);
	i=ret/25.4;
	c=ret2/25.4;
d=0;
f=0;
d=((i*i)+(c*c));
g=sqrt(d);
std::cout << "Your screen size in inches is " << g << "\" \n";
	getchar();
}


code of mydll.dll (mydll.cpp):
C++
// mydll.cpp : Defines the initialization routines for the DLL.
//

#include "stdafx.h"
#include "mydll.h"
#include <windows.h>
#include <iostream>
#include <complex>
#include <math.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

//
//TODO: If this DLL is dynamically linked against the MFC DLLs,
//		any functions exported from this DLL which call into
//		MFC must have the AFX_MANAGE_STATE macro added at the
//		very beginning of the function.
//
//		For example:
//
//		extern "C" BOOL PASCAL EXPORT ExportedFunction()
//		{
//			AFX_MANAGE_STATE(AfxGetStaticModuleState());
//			// normal function body here
//		}
//
//		It is very important that this macro appear in each
//		function, prior to any calls into MFC.  This means that
//		it must appear as the first statement within the 
//		function, even before any object variable declarations
//		as their constructors may generate calls into the MFC
//		DLL.
//
//		Please see MFC Technical Notes 33 and 58 for additional
//		details.
//

// CmydllApp

BEGIN_MESSAGE_MAP(CmydllApp, CWinApp)
END_MESSAGE_MAP()


// CmydllApp construction

CmydllApp::CmydllApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}


// The one and only CmydllApp object

CmydllApp theApp;


// CmydllApp initialization

BOOL CmydllApp::InitInstance()
{
	CWinApp::InitInstance();

	return TRUE;
}


void MyWin32ClassTwo()
{

			  double i,c,d,f,g,k;
			  char l; 
			  HDC hdc = GetDC(GetDesktopWindow());
    DWORD ret = GetDeviceCaps(hdc, HORZSIZE);
    DWORD ret2 = GetDeviceCaps(hdc, VERTSIZE);
      ReleaseDC(GetDesktopWindow(), hdc);
	i=ret/25.4;
	c=ret2/25.4;
d=0;
f=0;
d=((i*i)+(c*c));
g=sqrt(d);
}


how to create dll and add to win32 form (clr) application and call the dll's g variable, do I have to create function in dll?
simple answer please I am NEW to C++.
In simple how to get the horzsize of monitor in a C++ clr forms Project.

Thank you
Posted
Updated 11-Jan-15 0:14am
v3
Comments
Richard MacCutchan 11-Jan-15 6:33am    
Don't mix MFC with CLI, it does not work. Your DLL needs to be pure C/Win32.

1 solution

Yes you have to declare and export some functions if you want it in a dll. Best starting point is to create an C dll (with the project wizard) which exports some "naked" functions. Prefer static linking to avoid MFC and "dll hell".

My article Calling all stations is about C++ and C# interop with dlls, but the dll stays the same.

Tip: Dependency walker helps to see the dll-functions
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900