Quantcast
Channel: Visual C forum
Viewing all 15302 articles
Browse latest View live

how to fix the child dialog position inside a parent dialog

$
0
0

Hi, I am quite new to MFC development. I am looking to fix the child dialog inside a parent dialog, currently, I am getting the parent dialog positions and place the child dialog on the top right corner, but each time, when I move the parent dialog, the child dialog never moves. How can I resize it dynamically, or make it move as parent dialog moves. Here is my child dialog generation code.

  m_banner=new DialogTest();
	   if(m_banner!= NULL)
	   {
		   BOOL ret = m_banner->Create(IDD_DIALOGTEST, this);
		   if(!ret)   //Create failed.
           AfxMessageBox(_T("Error creating Dialog"));
		   m_banner->GetWindowRect(rect);
		   int dx = rect.Width();
		   int dy = rect.Height();
		   GetWindowRect(rect);
		   rect.left = rect.right - dx;
		   rect.bottom = rect.top + dy;
		   m_banner->MoveWindow(rect);
		   m_banner->ShowWindow(SW_SHOW);
}


warning C6387: 'fStream' could be '0':  this does not adhere to the specification for the function 'fclose'.

$
0
0

Here is a snippet of code:

bool CMeetingScheduleAssistantApp::ReadFromXML(CString strFileXML, tinyxml2::XMLDocument& rDocXML)
{
	FILE	*fStream = NULL;
	CString strError, strErrorCode;
	errno_t eResult;
	bool	bDisplayError = false;

	using namespace tinyxml2;

	// Now try to create a FILE buffer (allows UNICODE filenames)
	eResult = _tfopen_s(&fStream, strFileXML, _T("rb"));
	if (eResult != 0) // Error
	{
		bDisplayError = true;
		_tcserror_s(strErrorCode.GetBufferSetLength(_MAX_PATH), _MAX_PATH, errno);
		strErrorCode.ReleaseBuffer();
	}
	else // Success
	{
		// Now try to save the XML file
		XMLError eXML = rDocXML.LoadFile(fStream);
		if (eXML == XMLError::XML_SUCCESS)
		{
			// The XML data was loaded successfully!
			if (fclose(fStream) != 0)
			{
				// There was a problem closing the stream. We should tell the user
				bDisplayError = true;
				_tcserror_s(strErrorCode.GetBufferSetLength(_MAX_PATH), _MAX_PATH, errno);
				strErrorCode.ReleaseBuffer();
			}
		}
	}

	if (bDisplayError)
	{
		strError.Format(IDS_TPL_ERROR_READ_XML, strFileXML, strErrorCode, errno);
		AfxMessageBox(strError, MB_OK | MB_ICONINFORMATION);

		return false;
	}

	return true;
}

I get a code analysis warning on this line:

if (fclose(fStream) != 0)

warning C6387: 'fStream' could be '0':  this does not adhere to the specification for the function 'fclose'.

I am assuming this is a false positive because we test the return value of _tfopen_s. Isn't that enough?

CInternetSession::OpenUrl exception 12057:ERROR_INTERNET_SEC_CERT_REV_FAILED

$
0
0

We are trying to communicate to a host over SSL but the problem is that CInternetSession::OpenUrl Generates exception 12057:

CInternetSession isession;
CHttpFile* pFile = NULL;
CString httpadrstr = L"https://theadress.com";
DWORD dw;
char buffer[2048];
BOOL bret = TRUE;

try

{
isession.SetOption(INTERNET_OPTION_SECURITY_FLAGS, SECURITY_FLAG_IGNORE_REVOCATION);
pFile = (CHttpFile*)isession.OpenURL(httpadrstr, 1, INTERNET_FLAG_TRANSFER_ASCII  | INTERNET_FLAG_SECURE, NULL, 0);
pFile->QueryInfoStatusCode(dw);
switch (dw)
{
case 200:
pFile->Read(buffer, 2048);
break;
default:
bret = FALSE;
}
pFile->Close();
}
catch (CInternetException* pEx)
{
bret = FALSE;
pEx->Delete();
}

This code genrates the exception. If i paste the host adress in Opera or Edge it works fine. Any Idea?


warning C28183: 'HWND_FG' could be '0', and is a copy of the value found in 'HWND_PP':  this does not adhere to the specification for the function 'GetClassNameW'.

$
0
0

Here is another interesting issue. My code:

void CChristianLifeMinistryHtmlView::DoPrintPreview()
{
	HWND	  HWND_PP, HWND_FG ;
	TCHAR	  szClassName[256] ;
	ULONGLONG t1, t2 ;
	RECT	  workArea;

	ExecWB(OLECMDID_PRINTPREVIEW, OLECMDEXECOPT_PROMPTUSER, NULL, NULL);

    HWND_PP = NULL ;
	t1 = ::GetTickCount64();
	t2 = ::GetTickCount64(); // Extra line required for 'while' rearrangement.
	while (HWND_PP == NULL && t2 - t1 <= 6000) // if found or Timeout reached...
	{
		HWND_FG = ::GetForegroundWindow(); // Get the ForeGroundWindow
		::GetClassName(HWND_FG, szClassName, 256 );
		if (lstrcmp(szClassName, IE_PPREVIEWCLASS) == 0) // Check for Print Preview Dialog
			HWND_PP = HWND_FG ;

		theApp.PumpMessage();
		t2 = ::GetTickCount64();
	}

	if (HWND_PP != NULL)
	{
		// AJT V3.01 BUG Fix - showing maximized crops bottom of preview dialog
		::SystemParametersInfo( SPI_GETWORKAREA, 0, &workArea, 0 );
		::MoveWindow(HWND_PP, workArea.left, workArea.top,
			workArea.right - workArea.left,	workArea.bottom - workArea.top, TRUE);

	}

}

The code analysis warning this time is:

warning C28183: 'HWND_FG' could be '0', and is a copy of the value found in 'HWND_PP':  this does not adhere to the specification for the function 'GetClassNameW'.

It mentions two things there. But, for the first one, according to the documentation it states:

The return value is a handle to the foreground window. The foreground window can beNULL in certain circumstances, such as when a window is losing activation.

So I assume that NULL is going to be OK in some instances. And I confess I am unsure about the second part of the warning and why it is raised as an issue. My HTML View works. But if this can be fixed I am interested in learning what to do.

Thanks.

how to put child dialog on the top of the title and foot bar of the parent dialog

$
0
0
is there anyway to set the child dialog on the top of the title and foot bar of the parent dialog

bugfix program error help.

$
0
0

I've looked all around why strcpy won't work and can't seem to find an answer. please help!

#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef vector <string> StringList;
StringList Split(string orig, string delims)
{
	StringList list;
	int pos;
	while((pos = orig.find_first_of(delims)) != -1)
	{
		list.push_back(orig.substr(0, pos));
		orig = orig.substr(pos + 1);
	}
	list.push_back(orig);
	return list;
}
string MyUppercase(string str)
{
	char *buf = new char[str.length() + 1];
	strcpy(buf, str.c_str());
	strupr(buf);
	return string(buf);
}
string stripspaces(string orig)
{
	int left;
	int right;
	// If string is empty, just return it.
	if (orig.length() == 0)
		return orig;
	//Strip right
	right = orig.find_last_not_of("\t");
	if (right > -1)
	orig.resize(right + 1);
	// Strip left
	left = orig.find_first_not_of("\t");
	if (left > -1)
		orig.erase(0, left);
	/*If left still has a space, it
	means the whole string is whitespace.
	So just remove it all*/
	if (orig[0] == ' ' || orig[0] == '\t')
	{
		orig = "";
	}
	return orig;
}
void ProcessName(string name)
{
	StringList list;
	string first, middle, last;
	int size, commapos;
	name = stripspaces(name);
	commapos = name.find(" , ");
	if (commapos > 0)
	{
		//Name has a comma so start with last name.
		name.erase(commapos, 1);
		list = Split(name, " ");
		size = list.size();
		if (size > 0) last = list[0];
		if (size > 1) first = list[1];
		if (size > 2) middle = list[2];
	}
	else
	{
		//Name has no comma, start with first name.
		list = Split(name, " ");
		size = list.size();
		if(size > 0) first = list[0];
		if (size >2)
		{
			middle = list[1];
			last = list[2];
		}
		if (size == 2)
		{
			last = list[1];
		}
	}
	//If middle name is just initial and period, then remove the initial.
	if (middle.length() == 2)
	{
		if (middle[1] == '.')
		{
			middle.erase(1,1);
		}
	}
	//Convert all to uppercase
	first = MyUppercase(first);
	middle = MyUppercase(middle);
	last = MyUppercase(last);
	cout << "first: " << first << endl;
	cout << "middle: " << middle << endl;
	cout << "last: " << last << endl;
	cout << endl;
}
int main()
{
	string name;
	name = " Washington, George Zeus ";
	ProcessName(name);
	name = "Washington, George Z.";
	ProcessName(name);
	name = "George Z. Washington";
	ProcessName(name);
	name = "George Zeus Washington";
	ProcessName(name);
	name = "George Washington";
	ProcessName(name);
	system("pause");
	return 0;
}

error code

1>------ Build started: Project: BugProcessing, Configuration: Debug Win32 ------
1>  BugProcessing.cpp
1>c:\users\jonbecher\documents\visual studio 2012\projects\bugprocessing\bugprocessing\bugprocessing.cpp(23): error C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          c:\program files\microsoft visual studio 11.0\vc\include\string.h(110) : see declaration of 'strcpy'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Passing a structure doesn't work

$
0
0

I call a function in my DLL to initialize a structure address so the DLL gets the same data. 

When the DLL function runs, I see this:

The value of sp is 0x149a39e0, which looks right.  How come this address is not assigned to LENS1 in the dll?

Extract String from EXE

$
0
0
Hi,
I need to extract strings from a EXE file .  What are the ways to do that??

SetWindowPos doesn't take effect

$
0
0
I have a child dialog that is supposed to be on top of the title bar of the parent dialog, I am using setwindowpos, but nothing took effect. please help
	m_test = new DIALOGTEST(this);
	if (m_test != NULL)
	{
		m_test->Create(IDD_DIALOG1, this);
		m_test->ShowWindow(SW_SHOW);
		m_test->SetWindowPos(&CWnd::wndBottom, 0, 0, 0, 0,
			SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);

	}

possible to let the popup dialog move and resize as the main dialog moves?

$
0
0

I am trying to put a dialog on top of the other dialog's title bar. I tried child dialog, but it can not move up to title bar, popup dialog is able to, but it can not move as the main dialog moves or resize. any suggestions or code samples?

Thanks

Strong Name tool fails to work (VS2013)

$
0
0

D:\Bentleycode\OBMConnect\source\OpenBridge>C:\PROGRA~2\MIA713~1\Windows\v8.0A\bin\NETFX4~1.0TO\sn.exe -R "D:\Bentleycode\OBMConnect\out\Winx64\Build\OpenBridge\bin\Bentley.PowerBridge.Modeler.PBMECData.dll" D:\Bentleycode\OBMConnect\source\bsitools\anycpu\PublicPrgNonRightsCompliant.snk

Microsoft (R) .NET Framework Strong Name Utility  Version 4.0.30319.18020
Copyright (c) Microsoft Corporation.  All rights reserved.

Failed to re-sign the assembly -- The parameter is incorrect.

What's the reason for that? PBMECData.dll is CLR C++, I could not resign it! Any other way to walk around?

How do you add text to a CRichEditCtrl line by line?

$
0
0

CString str;

...GetWindowText(str)

str += "more text";

...SetwindowText(str);

Does not work.

...SetCurSel(-1, -1);

...ReplaceSelection("more text")

Does not work either.

All I am getting is the first line of text that I add then all all subsequent lines I add are ignored.

Why?

compile crimson editor source code in Visual C++ 6

$
0
0
When I download Crimson editor, now called Emerald editor, from this page.
I have to raise privileges to run the editor in windows 7.
Can someone please compile the source, so the editor can be used in windows 7 normally? The source seemsto be here. Itsays here it can be "compiled with Microsoft Visual C++ 6.0".

 

Interop problem between DLL C++ MFC and CLI [TypeLoadException and more]

$
0
0
Hi all,

After 3 days of researches in the depths of Google and all dev forums, I'am asking for your help.

I'm doing dev / c ++ linux for more than 10 years, but today I have a new job and they ask me to develop on Windows environment with Visual Studio. I'm in the middle of the authorized period of self-training and despite hundreds of websites on about this subject I  am really not comfortable with the notions of managed object, COM, and finally... all the .NET environment ^^ So I am totally lost and no colleague to help me.

Today I have to write a DLL that contains a class with its pretty methods, and which creates a custom dialog box in which programs must send text messages. 

I specify: programs that use this DLL are written in C ++ MFC, C #, C ++ / CLI, delphi and Python ... 

So after several liters of sweat I wrote it in C ++ MFC, to have a dialog and a simple use with the outside. That I thought...

I managed to use C#, using the IUnknown interface and a small method to create an instance of my class.

In C ++ MFC I use it easily.

Where I'm blocked for 3 whole days this is for the C ++ / CLI. And that's where I need you!

Clearly I can call a basic method, but I can not create my graphic object and not call the constructor of my mfc class.


DLL header :

#ifdef CPPDLL_EXPORTS
#define CPPDLL_API __declspec(dllexport)
#else
#define CPPDLL_API __declspec(dllimport)
#endif


#include <Windows.h>

// Generate from Visual Studio, Menu "Tools/Create GUID"
// {0D825F4E-7028-4628-8EBA-BBF77610EC7E}
static const GUID IID_IMyInterface =
{ 0xd825f4e, 0x7028, 0x4628,{ 0x8e, 0xba, 0xbb, 0xf7, 0x76, 0x10, 0xec, 0x7e } };
struct IMyInterface : public IUnknown // COM Interface. Enables clients to get pointers to other interfaces on a given object through the QueryInterface method.
{
	STDMETHOD_(double, GetValue)() = 0;
	STDMETHOD(CustomMsgBox)(const char*) = 0;
};

// This class is exported from the MyClass.dll
class CPPDLL_API CMyClass: public IMyInterface
{
	volatile long refcount_;
public:
	CMyClass() : refcount_(1) {};

	STDMETHODIMP QueryInterface(REFIID guid, void **pObj)
	{
		if (NULL == pObj) {
			return E_POINTER;
		}
		else if (guid == IID_IUnknown) {
			*pObj = this;
			AddRef();
			return S_OK;
		}
		else if (guid == IID_IMyInterface) {
			*pObj = this;
			AddRef();
			return S_OK;
		}
		else {
			// Always set 'out' parameter
			*pObj = NULL;
			return E_NOINTERFACE;
		}
	}

	STDMETHODIMP_(ULONG) AddRef() {
		return InterlockedIncrement(&refcount_);
	}

	STDMETHODIMP_(ULONG) Release() {
		ULONG result = InterlockedIncrement(&refcount_);
		if (result == 0) delete this;
		return result;
	}

	STDMETHODIMP_(DOUBLE) GetValue() {
		return 3.14;
	}

	STDMETHODIMP ThrowError() {
		return E_FAIL;
	}

	CMyClass(int p_flagDebug, CWnd* p_Parent);
	CMyClass(int p_flagDebug, int left, int top, int right, int bottom);
	~CMyClass();
	// TODO: add your methods here.
	void WriteMessage(CString p_sMsg);
	void WriteMessage(const wchar_t* p_sMsg);
	void InitDlg();
	STDMETHODIMP CustomMsgBox(const char* p_sStr = nullptr);

private:
	void AppendText(HWND hEditWnd, LPCTSTR Text);
	void DoIt(const char *p_sStr, long p_lNumber);
	void *m_gui; // Handle on the child dialog.
	CWnd *m_parent; // Handle on parent used to get the window position
	int m_Flag;
};


extern "C" CPPDLL_API LPUNKNOWN WINAPI CreateInstance(int FlagDebug, void* cwnd);

extern CPPDLL_API int nMyClass;

CPPDLL_API int fnMyClass(void);


DLL Code :

// MyClass.cpp : Defines the exported functions for the DLL application.
// @TODO : Manage close event of our Gui !!! (Actually nothing is done)

#include "stdafx.h"
#include "MyClass.h"
#include "Gui.h"
#include <Dbghelp.h>
#include <windowsx.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


#pragma comment(lib, "dbghelp.lib")

// The one and only application object
CWinApp theApp;

HMODULE hModule; // Handle on this module
WNDPROC PrevPresLVWndProc; // Pointer to parent callback function
struct s_dialog {
	CGui* g_gui;
	CWnd* g_parent;
	int g_parentTop;
	int g_parentLeft;
	int g_parentRight;
	int g_parentBottom;
};
s_dialog g_dlg;

void SetGuiPosition(void);
LRESULT CALLBACK ParentCallback_OnMove(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);


/// <summary>
/// Constructor
/// </summary>
/// <param name="p_Parent">Parent CWND</param>
CMyClass::CMyClass(int p_flag, CWnd* p_Parent)
{
	if (NULL == p_Parent->m_hWnd)
	{
		AfxMessageBox(_T("CMyClass object creation may be before main dialog initialization"), MB_OK | MB_ICONERROR);
		return;
	}

	m_Flag = p_flag;

	if (m_Flag == 1)
	{
		// Initilization of the global struct g_dlg
		g_dlg.g_parent = m_parent = p_Parent;
		g_dlg.g_gui = NULL;
		m_gui = NULL;

		// Here we save pointer of the parent process
		PrevPresLVWndProc = (WNDPROC)GetWindowLongPtr(m_parent->m_hWnd, GWL_WNDPROC);
		// Now we associate the new callback method for event
		SetWindowLongPtr(m_parent->m_hWnd, GWL_WNDPROC, (LONG_PTR)&ParentCallback_OnMove);

		// Creation of our gui dialog
		CGui* mGuiLoc = new CGui;
		AFX_MANAGE_STATE(AfxGetStaticModuleState());
		m_gui = (void*)(new CGui());
		BOOL ret = ((CGui*)m_gui)->Create(MAKEINTRESOURCE(IDD_DIALOG1));
		((CGui*)m_gui)->ShowWindow(SW_SHOW);
		// Setting the dialog text
		((CGui*)m_gui)->m_EditBox.SetWindowText(_T("Text to display\r\n"));
		g_dlg.g_gui = ((CGui*)m_gui);
		InitDlg();
	}
}
CMyClass::CMyClass(int p_flag, int left, int top, int right, int bottom)
{
	m_Flag = p_flag;
	// Empty for the moment
}

/// <summary>
/// Destructor
/// </summary>
CMyClass::~CMyClass()
{
	SetWindowLongPtr(m_parent->m_hWnd, GWL_WNDPROC, (LONG_PTR)&PrevPresLVWndProc);
}

/// <summary>
/// Non member function - It is the new callback used to catch parent event
/// </summary>
/// <param name="all">that's default param used for this kind of callback method and content depends of message type (uMsg)</param>
LRESULT CALLBACK ParentCallback_OnMove(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	if (uMsg == WM_MOVE)
	{
		CRect rectGui;
		g_dlg.g_gui->GetWindowRect(&rectGui);
		CString s;
		s.Format(_T("gui top"));
		OutputDebugString((LPCTSTR)s);
	}
	return CallWindowProc(PrevPresLVWndProc, hwnd, uMsg, wParam, lParam);
}

LPUNKNOWN WINAPI CreateInstance(int p_flag, void* cwnd) {
	return new CMyClass(p_flag, CWnd::FromHandle((HWND)cwnd));
}


/// <summary>
/// Initialize Gui
/// </summary>
void CMyClass::InitDlg()
{
	if (m_Flag == 0) return;

	if (NULL == m_gui)
	{
		//SetGuiPosition();
	}
	else
	{
		if (((CGui*)m_gui)->IsWindowVisible() != TRUE)
		{
			((CGui*)m_gui)->ShowWindow(SW_SHOW);
		}
	}
}

/// <summary>
/// Add a message to Edit Box
/// </summary>
/// <param name="p_sMsg">The message to print</param>
void CMyClass::WriteMessage(CString p_sMsg)
{
	if (m_Flag == 0) return;

	InitDlg();
	if (NULL != m_gui)
	{
		AppendText(((CGui*)m_gui)->m_EditBox, p_sMsg);
	}
}

/// <summary>
/// Add a message to Edit Box - Compatibility for others languages
/// </summary>
/// <param name="p_sMsg">The message to print</param>
void CMyClass::WriteMessage(const wchar_t* p_sMsg)
{
	if (m_Flag == 0) return;

	CString csMsg(p_sMsg);
	WriteMessage(csMsg);
}

/// <summary>
/// Append a message to Edit Box
/// </summary>
/// <param name="p_hEditWnd">Handle on Edit Box</param>
/// <param name="p_text">The message to print</param>
void CMyClass::AppendText(HWND p_hEditWnd, LPCTSTR p_text)
{
	if (m_Flag == 0) return;

	int idx = GetWindowTextLength(p_hEditWnd);
	SendMessage(p_hEditWnd, EM_SETSEL, (WPARAM)idx, (LPARAM)idx);
	SendMessage(p_hEditWnd, EM_REPLACESEL, 0, (LPARAM)p_text);
}

/// <summary>
/// Display one message
/// <param name="p_sStr">Name</param>
/// </summary>
HRESULT CMyClass::CustomMsgBox(const char* p_sStr)
{
	if (m_Flag == 0) return S_OK; // Useless

	InitDlg();

	size_t outSize;
	wchar_t *wsStr = new wchar_t[256];
	// Conversion char* to wchar_t*
	mbstowcs_s(&outSize, wsStr, strlen(p_sStr) + 1, p_sStr, strlen(p_sStr));

	CString sTime(CTime::GetCurrentTime().Format("%H:%M:%S"));
	CString sMessage;
	sMessage.Format(_T("%s;%s;-\r\n"), sTime, wsStr);
	WriteMessage(sMessage);
	return S_OK;
}


void CMyClass::DoIt(const char *p_sStr, long p_lNumber)
{
	size_t outSize;
	wchar_t *wsStr = new wchar_t[256];
	// Conversion char* to wchar_t*
	mbstowcs_s(&outSize, wsStr, strlen(p_sStr) + 1, p_sStr, strlen(p_sStr));

	CString sTime(CTime::GetCurrentTime().Format("%H:%M:%S"));
	CString sMessage;
	sMessage.Format(_T("%s;%s;%d\n"), sTime, wsStr, p_lAllParamSum);

	WriteMessage(sMessage);
}

 

C# code used to call MFC DLL class methods :

using System;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Forms;

/***
USAGE :
1 : Create a pointer on this object and initialize it ONLY after main dialog init !
2 : Create ONLY ONE object
Example to create object :
    CMyClass myCClassInstance = new CMyClass();
    IMyInterface myObjectInterface = myCClassInstance.LocCreateInstance();
    Console.WriteLine(myObjectInterface.GetValue());
***/


namespace MyNamespace
{
    [ComImport]
    [Guid("0D825F4E-7028-4628-8EBA-BBF77610EC7E")]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IMyInterface
    {
        [PreserveSig]
        double GetValue();
        IntPtr CustomMsgBox([MarshalAs(UnmanagedType.LPStr, SizeParamIndex = 3)] string str);
        void ThrowError();
    }
    ////////////////////////////////////////////////////////////
    // Inclusion of other needed stuff
    ////////////////////////////////////////////////////////////

    public class CMyClass
    {
        [DllImport("MyClass.dll")]
        extern static IMyInterface CreateInstance(int Flag, IntPtr o2);

        public IMyInterface LocCreateInstance(IntPtr o1)
        {
            return CreateInstance(1, o1);
        }
    }
}

 

This is the C++/CLI code I'm trying to do, I have and beautiful exception System.TypeLoadException : 

header :

using namespace System;
using namespace System::Text;
using namespace System::Runtime::InteropServices;
using namespace System::Windows::Forms;

namespace company
{
	namespace project
	{
		namespace module
		{
			public interface class IMyInterface
			{
				double GetValue();
			};

			public ref class CMyClass : IMyInterface //ref class CMyClass
			{
				public:
				CMyClass() {};

				[DllImport("MyClass.dll", EntryPoint = "_CreateInstance@8Z", CallingConvention = CallingConvention::StdCall)]
				IMyInterface^ CreateInstance(int Flag, IntPtr cwnd);

				[DllImport("MyClass.dll", EntryPoint = "?GetValue@CMyClass@@UAGNXZ", CallingConvention = CallingConvention::StdCall)]
				virtual double GetValue();
			};
		}
	}
}

Code :

	CMyClass^ m_cMyClass = gcnew CMyClass();
	IMyInterface ^m_i_MyInterface = m_cMyClass->CreateInstance(1, this->Handle);

Bellow the exception I catch :

	-		e	{"Méthode implémentée PInvoke virtuelle.":"company.project.module.CMyClass"}	System::Exception^ {System::TypeLoadException^}
		AssemblyName	"PCExample, Version=1.0.6198.29074, Culture=neutral, PublicKeyToken=null"	System::String^
		ClassName	"company.project.module.CMyClass"	System::String^+		Data	{System::Collections::ListDictionaryInternal^}	System::Collections::IDictionary^ {System::Collections::ListDictionaryInternal^}
		HResult	-2146233054	int
		HelpLink	nullptr	System::String^+		IPForWatsonBuckets	{28553626}	System::UIntPtr+		InnerException	nullptr	System::Exception^
		IsTransient	false	bool
		Message	"Méthode implémentée PInvoke virtuelle."	System::String^
		MessageArg	nullptr	System::String^
		RemoteStackTrace	nullptr	System::String^
		ResourceId	8209	int
		Source	"PCExample"	System::String^
		StackTrace	"   à PCExample.FormMain..ctor()\r\n   à main(String[] args) dans d:\\proje\\PCExample\\checkit\\c++_clr\\PCExample\\PCExample.cpp:ligne 19"	System::String^+		TargetSite	{Void .ctor()}	System::Reflection::MethodBase^ {System::Reflection::RuntimeConstructorInfo^}
		TypeName	"company.project.module.CMyClass"	System::String^
		WatsonBuckets	nullptr	System::Object^
		_HResult	-2146233054	int
		_className	nullptr	System::String^+		_data	{System::Collections::ListDictionaryInternal^}	System::Collections::IDictionary^ {System::Collections::ListDictionaryInternal^}
		_dynamicMethods	nullptr	System::Object^+		_exceptionMethod	{Void .ctor()}	System::Reflection::MethodBase^ {System::Reflection::RuntimeConstructorInfo^}
		_exceptionMethodString	nullptr	System::String^
		_helpURL	nullptr	System::String^+		_innerException	nullptr	System::Exception^+		_ipForWatsonBuckets	{28553626}	System::UIntPtr
		_message	"Méthode implémentée PInvoke virtuelle."	System::String^
		_remoteStackIndex	0	int
		_remoteStackTraceString	nullptr	System::String^+		_safeSerializationManager	{System::Runtime::Serialization::SafeSerializationManager^}	System::Runtime::Serialization::SafeSerializationManager^
		_source	"PCExample"	System::String^+		_stackTrace	array<char>(48)	System::Object^ {array<char>^}
		_stackTraceString	nullptr	System::String^
		_watsonBuckets	nullptr	System::Object^
		_xcode	-532462766	int+		_xptrs	{0}	System::IntPtr+		[Static Members]	

It is really important for me to understand and succed...

I hope you will understand my problem and help me. And I apologize about my english !

For information : I use the same target platform and same toolset. DLL is working really fine with C# and C++/MFC.

Thanks by advance,

nb

 

 

 

 

 



Function exceeds stack size

$
0
0

How do I go about resolving a warning like this?

warning C6262: Function uses '37648' bytes of stack:  exceeds /analyze:stacksize '16384'.  Consider moving some data to heap.

My method:

void CChristianLifeMinistryEditorDlg::OnBnClickedButtonOclmEditStudentAssignments()
{
	if (m_pEntry != NULL)
	{
		CChristianLifeMinistryStudentsDlg dlgStudents(this);

		if (IsModified())
			UpdateMeetingForDate(); // Get things in the right state

		RebuildStudentHistory();

		dlgStudents.SetStudentAssignHistoryPtr(&m_arySPtrStudentHist);
		dlgStudents.SetAssignedStudyPointsMapPtr(&m_mapStudentAssignedStudyPoints);
		dlgStudents.SetEntry(m_pEntry); // The student dialog will update the pointer
		if (dlgStudents.DoModal() == IDOK)
		{
			SetModified(true);
		}
	}
}


Changing shape of a caret

$
0
0

Guys, from here:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms646968(v=vs.85).aspx

I've learned that caret can have different shapes. I've tried to create caret but the only shape I'm able to get is a vertical line. How can I create different shapes, particularly I'm interested in underline shape and block.

Thank you.

Are move constructors/assignment operators automatically generated

$
0
0

Back in 2010, I learned about move semantics when they were first added to VC++. Back then, move ctors/assignment operators were not automatically generated, but this seems to have changed a dozen times and I have better things to do than keep up with the standards committee's whims.

What are the current rules for generating move ctors/assignment operators and how are they implemented in VC++? Also are there any differences between VC++ 2013 and 2015?

Getting a list of serial ports in Windows 10

$
0
0

The following code has worked on a number of Windows 10 machines, but I have just found one where it does not work because the registry of this particular copy of windows 10 does not have a SERIALCOMM folder.

The system COM ports must be listed some where so, if not under SERIALCOMM, then where?

void CSerialPort::GetCOMPorts(CStringArray &strarrayCOMPorts, CWnd *pWnd)
{
	CRegKey regkey;
	DWORD dwI = 0, nBuffSize = BUFF_SIZE;
	char szKeyName[BUFF_SIZE], szKeyVal[BUFF_SIZE];
	LONG nCode = ERROR_SUCCESS;
	CString strKeyVal, strTemp, strResponse;
	UINT nCOMPort = 0;
	CSerialPort SerialPort;

	memset(szKeyName, 0, BUFF_SIZE);
	memset(szKeyVal, 0, BUFF_SIZE);
	if (regkey.Open(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\SERIALCOMM", KEY_READ) == ERROR_SUCCESS)
	{
		//LONG WINAPI RegEnumValue(_In_        HKEY    hKey,
		//							_In_        DWORD   dwIndex,
		//							_Out_       LPTSTR  lpValueName,
		//							_Inout_     LPDWORD lpcchValueName,
		//							_Reserved_  LPDWORD lpReserved,
		//							_Out_opt_   LPDWORD lpType,
		//							_Out_opt_   LPBYTE  lpData,
		//							_Inout_opt_ LPDWORD lpcbData);
		do
		{
			nCode = RegEnumValue(regkey.m_hKey, dwI, szKeyName, &nBuffSize, NULL, NULL, NULL, NULL);
			if (nCode != ERROR_NO_MORE_ITEMS)
			{
				nBuffSize = BUFF_SIZE;
				regkey.QueryStringValue(szKeyName, szKeyVal, &nBuffSize);
				nBuffSize = BUFF_SIZE;
				strKeyVal = szKeyVal;
				strTemp = strKeyVal;
				strTemp.Delete(0, 3);
				nCOMPort = atoi(strTemp);
				if ((nCOMPort >= 1) && (SerialPort.Open(strKeyVal)) && (SerialPort.isIrrigationController(strKeyVal)))
				{
					SerialPort.Write("id#");
					if (SerialPort.Read(strResponse, 2000) > 0)
					{
						strarrayCOMPorts.Add(strResponse + " (" + strKeyVal + ")");
					}
				}
				SerialPort.Close();
				dwI++;
			}
		}
		while (nCode != ERROR_NO_MORE_ITEMS);
	}
	else
		AfxMessageBox("Cannot access the Windows registry...", MB_OK);
}

form display on monitor -is it possible in VS, suing C++?

$
0
0

Hi, VS experts out there?

I am new to VS.  I am using html, php and MySQL.   I would appreciate that someone guides me on the possibility of

displaying on monitor, data looking like a checking account bank statement.    Is one of the prerequisite  accessing database, using VS script?   Is the form setup and display by way of C++?  

Thanking you in advance!

cbo 


cbo

form display on monitor -what is the best method in VS?

$
0
0

Dear VS experts:

Please guide me to approach the best way of developing an app and displaying form on a monitor?

Input be from database and the form profile can be like a bank checking account statement, listing daily credit & debit.

Thanks in advance!

cbo


cbo

Viewing all 15302 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>