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

Detecting when a Client attaches to my OLE/COM server

$
0
0

We have an OLE/COM server application that exposes a rather large API to users. I really need to know when an API attaches and releases the server. For example knowing when someone attaches by calling GetObject( ) on our interface. I'm thinking that I need to override the default/automatic IUnknown interface AddRef() and Release() methods, however I'm not quite sure how to do that. Maybe this is the wrong approach and there is another way.  


Hovering shows A (not W) info in a Unicode project

$
0
0

VS 2019

I have Properties ... Advanced ... Use Unicode Character Set.  But when I hover on the name of a function or struct devenv shows me the "A" define/typedef information (rather than the "W" info).  Can I change that ?

Thanks.

 - Vince

IF Statement Error?

$
0
0
Hello Everyone, One of my friend was suggested to me this is the biggest community where I can find my solution. I am tried to make C++ based calendar. Some one help me to get February to print with 29 days during a leap year? I don't know whats the exact problem is this or any suggestion to C++ tutorial, I want to grow my technical skills more.

Calling tests methods

$
0
0

Other languages like Rust or Java have tags @Test for test methods and simply can be run.

Is posssible something similar in C++?

wglMakeCurrent fails error 2004

$
0
0

MDI MFC application . Trying to migrate to OpenGL.

wglMakeCurrent fails with error 2004 when different views are activated. Each CView object has its own DC and rendering context.

No idea how to solve.

Thanks

Open a new dialog from A window toaster click in c++

$
0
0

HI,

I have used Windows code (https://github.com/WindowsNotifications/desktop-toasts)and implemened a new toaster message message for Win32. is there any way to open another exe when i click on the toaster message?

Generally Shellexecute can open in c++ win32 but i am not able to open using the same when i am handling on toaster click event.

Thank you for the help!!

 



Regards, Ravi Raj Nukala

LNK1104 cannot open file 'mfc140d.lib'

$
0
0

I installed VS 2017 on a Windows 7 laptop, loaded my C++ project, selected "Retarget solution" to upgrade from VS 2012, debug-configuration recompiled the project, and got the error message that is the title of this inquiry. How do I resolve it? Any hints?

The project uses multi-byte character set, not Unicode. I will eventually upgrade it Unicode, but I have other issues to tackle first, so I'd like to avoid Unicode for now.


Peter

Disable Aero for all applications running on system on Windows 10

$
0
0

Hi

I am currently on a project for which I need to be able to get the colours working correctly for the legacy MFC application we use at work. Since moving to Windows 10 and microsoft having removed the classic theme it has caused many problems for the application in the way it looks. 

In order for the window title bars to look like the classic versions on windows 10 which means I want to programatically write a code which would disable non-client area rendering.

Shown below in the screenshot link, I want whats on the right but I want it for all applications running rather me personally having to make changes to each application. 

// https://gyazo.com/ab47db7088d780adb62e077ae6a8f2f2 // 

Thanks
PLEASE HELP! 


COM security : Different user accessing COM createobject throws permission error

$
0
0

I have a scenario below. Have COM legacy application which we use for automation of batch. This COM is an exe running in mixed mode having VC++ and .Net code exposing general methods for automation.

I have setup Components and services (dcom config) security for this COM component to have lauched using This user (its service account) and under security provided full access to all security customize buttons to this user and another user who would be actually running this batch(batch user) from another machine.

But when batch user tries to createobject, it gives permission denied error, even on this same machine.

This batch user and current COM launching user (service account) are having ADMINS rights, any other thing I need to check ?. The requirement is to have same above batch user running COM API's for batch and not service account.

regards

kirann

VC++ 2019 (64Bit) Loading DLL built from Labview 2017 64Bit.

$
0
0

Hi,

I am struggling to figure out how to use a DLL that I have created in Labview 2017 (64 bit). I have created a minimal DLL and VC++ code base to share here to hopefully find a solution to the error with the DLL not loading (the error is described below). The DLL (and others I have made) work fine when I use them with MatLab 2015b. But VC++ is just not working for me!

I am using Visual Studio 2019 C++ and took the following steps to create the simple project:

  • I started with an Empty c++ project.
  • Changed the Linker>System>SubSystem from blank to: Windows (/SUBSYSTEM:WINDOWS)
  • Changed the Linker>Advanced>Entry Point from blank to: main
  • Right-Clicked on the project to choose Add>New Item. 
  • Then chose "Visual C++">UI>Windows Form (Creating MyForm).
  • Added the main(..) function to the MyForm.cpp
  • A text field is added to the form (InputField)
  • A second text field is added to the form (OutputField)
  • A Button is added to the form (Button1)
  • Double click on the new Button to automatically create the event: Button1_click(...)" at the bottom of MyForm.h
  • The code for the Button1_click() is show below.
  • I have tried adding the path of the DLL/LIB/h files to the Properties>VC++ directories (Include and Library Directories) but it made no difference. All those files are located next to the project and other source files anyhow.

The Error I receive when I Build is LNK2028, LNK2019, and LNK1120 (see the image below)

Error	LNK2028	unresolved token (0A000008) "extern "C" double __cdecl MyIncrement(double)" (?MyIncrement@@$$J0YANN@Z) referenced in function "private: void __clrcall MyTestApp::MyForm::Button1_Click(class System::Object ^,class System::EventArgs ^)" (?Button1_Click@MyForm@MyTestApp@@$$FAE$AAMXPE$AAVObject@System@@PE$AAVEventArgs@4@@Z)	MyTestApp	C:\Users\kane\source\repos\MyTestApp\MyForm.obj	1	
Error	LNK2019	unresolved external symbol "extern "C" double __cdecl MyIncrement(double)" (?MyIncrement@@$$J0YANN@Z) referenced in function "private: void __clrcall MyTestApp::MyForm::Button1_Click(class System::Object ^,class System::EventArgs ^)" (?Button1_Click@MyForm@MyTestApp@@$$FAE$AAMXPE$AAVObject@System@@PE$AAVEventArgs@4@@Z)	MyTestApp	C:\Users\kane\source\repos\MyTestApp\MyForm.obj	1	
Error	LNK1120	2 unresolved externals	MyTestApp	C:\Users\kane\source\repos\MyTestApp\x64\Debug\MyTestApp.exe	1	

The MyForm.h header consists of:

#pragma once
#include "MySimpleTest.h"" //DLL Header

namespace MyTestApp {
	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

/*...
and so on and so on... standard form items etc. Below, 
Button1_Click(...) is the peice of code that calls the 
DLL function "double MyIncrement(double)" when the
Button1 is pressed. The function Reads value from the
InputField, Increments the value, and writes it to the 
OutputField. That is all! To activate the DLL call, 
set the #define UseDLLCall to true (but will cause an error).
...*/

private: System::Void Button1_Click(System::Object^ sender, System::EventArgs^ e) {
   double a,b;
   /*CHANGING THE LINE BELOW TO true CAUSES COMPILE ERRORS*/
   #define UseDLLCall false
   a = System::Convert::ToInt32((InputField->Text));
#if UseDLLCall
   // Use the DLL to do the Increment: NOTE, this results in
   // the error I can not resolve!!!!!!
   b = MyIncrement(a); //This is the DLL Call
#else
   // Do the increment maths without the DLL.
   b = a + 1;
#endif
   OutputField->Text = System::Convert::ToString(b);
}
};
}

The MyForm.cpp is:

#include "MyForm.h"
using namespace System;
using namespace System::Windows::Forms;

[STAThreadAttribute]
int main(array<String^>^ args) {
	Application::EnableVisualStyles();
	Application::SetCompatibleTextRenderingDefault(false);
	MyTestApp::MyForm form;
	Application::Run(% form);
	return 0;
}

The DLL files ... 
  MySimpleTest.dll
  MySimpleTest.lib
  MySimpleTest.h
... are all together inside the VC++ project folder, along with the files ...
  MyForm.h
  MyForm.cpp
  MyTestApp.h
  MyTestApp.sln
  MyTestApp.vcxproj

The DLL Header MySimpleTest.h is:

#ifdef __cplusplus
extern "C" {
#endif

// The DLL call "MyIncrement() simply returns "Input + 1".
double __stdcall MyIncrement(double Input);
long __cdecl LVDLLStatus(char *errStr, int errStrLen, void *module);
void __cdecl SetExcursionFreeExecutionSetting(long value);

#ifdef __cplusplus
} // extern "C"
#endif

Does anyone know what the problem is? Many thanks in advance!

The project and source can be downloaded from here:

(It won't let me post a link)

Kind regards,

Kane.


Missing versions of visualC + +

$
0
0

I keep getting a message when windows starts up saying The code execution cannot proceed because MSVCP110.d11 was not found reinstalling program may fix this problem What is the best thing to do 

Regards Len

Output file is missing

$
0
0

The following code, extracted from a larger program, seems to work correctly. But there is no sign of the output file anywhere.

Can anyone see what needs to be changed to cure this problem?

C++ PROGRAM:

char *in_filename ;
char *out_filename ;

// The in_filename and the out_filename have the command arguments as their values:
// "C:\Storage\JGW\Research\Dev\2018plus\LANGS\LANG1\LANG1\Debug\in\gr1.txt"
// "C:\Storage\JGW\Research\Dev\2018plus\LANGS\LANG1\LANG1\Debug\out\o_gr1.txt"

ifstream ifile("in_filename",ios::ate); // Leaving off the quote marks leads to an assertion failure.

// The input part of the larger program seems to work correctly.
// But there is no sign of the output file anywhere when the program exits.

ofstream ofile("out_filename",ios::ate); // Leaving off the quote marks leads to an assertion failure.

ofile.open(out_filename) ;
if(ofile.is_open() == false)
    abort_run("Unable to open output file.\n") ;

// Test message

ofile << "Test message." ;
ofile.close();
exit(0) ;


GerryWolff

Check the CheckBox through the code

$
0
0

Hi Team,

I have the CheckBox in my MFC Application and want to check it through the code by getting the input from field bool IsManual.

if(IsManual)

    Check the CheckBox

else

UnCheck the Checkbox

Please help me and if possible please given me an example.Thank you

Regards,

SenthilAndavan

Long titles in tile views (CListCtrl)

$
0
0

Hello MFC devolopers,

I try to use the list control (CListCtrl) in tile view mode. That basically works.

But now, we like to use long, descriptive texts as title of the items.

STRINGTABLE
BEGIN
    IDS_VIEW_LAYOUT_1    "Treeview (Alt+T)"
    IDS_VIEW_LAYOUT_2    "Channel list (Alt-C)"
    IDS_VIEW_LAYOUT_3    "Treeview and Channel list (horizontally arranged)"
    IDS_VIEW_LAYOUT_4    "Treeview and Channel list (vertically arranged)"
    IDS_VIEW_LAYOUT_5    "Device list and Channel list (horizontally arranged)"
    IDS_VIEW_LAYOUT_6    "Treeview and Device list\n(upper section, vertically arranged), Channel list (lower section)"
    IDS_VIEW_LAYOUT_7    "Treeview (left section) Device list and Channel list (right section, horizontally arranged)"
END

Here the first 5 items look good, the first two fit into one line and the next three are automatically wrapped.  

But for the last two items, the title is truncated.

      (Here I wanted to include a screenshot. But the MDSN forum forbids me to upload images.)

Is there a way to wrap the long title over more than 2 lines? Or any other solution to display long titles?

Regards
Friedbert

C++ Class and Functions

$
0
0
I have a code I am working on, but have been working on it for too long. The functions work independently of each other, but together they do not. As well, could someone give me an laymens explanation on functions. I have read, and I have read but they still confuse me. Hence why my code is not working. I have tried declaring int a, b, and c in a few spots but it nothing works. If someone could look at it and point me in the direction on where I need to focus my attention, I would really appreciate it.
#include "pch.h"
#include <iostream>
#include <conio.h>
using namespace std;

int gcd(int a, int b)
{

	if (a= 0)
		return b;
	return gcd(b % a, a);
}

class Fraction
{
	int numerator, denominator, whole_number;
	int newFraction;	
	
public:
	int a;
	int b;
	int c;
	
	const static char Slash;
	char aSlash();
	int enterFractionValue();	
	void setValues(int a, int b, int c);
	int reduceFraction(int a, int b, int c);
	void displayFraction();	

};

const char Fraction::Slash = '/';

char Fraction::aSlash()
{
	return Slash;
}

int Fraction::enterFractionValue()
{
	
	while ((whole_number != 0) && (numerator != 0))
	{
		//Read whole_number 
		cout << "Enter a whole number: >> ";
		cin >> whole_number;
		//Read numerator
		cout << "Enter a numerator: >> ";
		cin >> numerator;
		//Read denominator
		cout << "Enter a denominator: >> ";
		cin >> denominator;
		while (denominator == 0)
		{
			cout << "Zero is not a valid dominator value" << endl;
			cout << "Enter a different denominator value: >> ";
			cin >> denominator;
		}		
		return whole_number, numerator, denominator;
	}	
};

void Fraction::setValues(int a, int b, int c)
{
	this->whole_number = a;
	this->numerator = b;
	this->denominator = c;
}

int Fraction::reduceFraction(int a, int b, int c)
{	
	int gcf;
	int y;
	if (b >= c)
	{
		a += b / c;
		b = b % c;
	}
	gcf = 1;
	for (y = b; y > 0; --y)
	{
		if (b % y == 0 && c == 0)
		{
			gcf = y;
			y = 0;
		}
	}
	b /= gcf;
	c /= gcf;	
	return (a, b, c);
	//test output
	cout << a << " " << b << "/" << c << endl;
}
void Fraction::displayFraction()
{	
	cout << a << " " << b << Slash << c << endl;
}

int main()
{
	Fraction newFraction;
	int a;
	int b;
	int c;
	
	
		newFraction.enterFractionValue();
		newFraction.setValues(a, b, c);		
		newFraction.reduceFraction(a, b, c);
		newFraction.displayFraction();

	return 0;
}


Encyption Component in C++ and C#

$
0
0
does anyone knows any free (open source preferred) encryption component or dll that can be used both in MFC C++ and also C# with interopservices.I am in urgent need of such thing!
the problem is the MFC C++ code which was written with VS6 does not support .NET framework. I have to
use a method which encrypt the data in the C++ code and decrypt it inside C# or vise versa.

On VirtualAlloc's preferred addresses

$
0
0

Hi!

I'm developing a low-level memory manager library for C++ and I would like to know how theVirtualAlloc* functions choose the addresses that they return.

In particular I'd like to know the following:

  • Does VirtualAlloc* return the lowest available address?
  • Is there a chance that a future call to VirtualAlloc* might return a lower address than the one returned by the first call to it in the entire program?
  • Does MEM_LARGE_PAGES alter the strategy by which addresses get chosen? Aside from the increase of the allocation granularity?

Any answers are greatly appreciated :)



Hard Disk Serial Number

$
0
0
Hey , 

I have a question which I really hope someone can help me.
I have been dealing for a long time with finding a real unique ID for Hard Disks (slaves).
From all the forums and articles the answer I got is "Serial Number".
Is that true ? Is serial number is the only and best unique ID to recognize HD ? 
The reason I'm asking that question is that I wrote a program in c++.One of the things it does is 
getting with WMI command the HDs' serial numbers that connect to the station. 
Through the time I noticed that sometimes I get for the same HD different serial numbers or 
similar serial number but the characters changed their place.

Are you familiar with this problem ? Is there better unique ID should I use ? Is there a better call than WMI ? 

Thanks !   

eden

Appcore.cpp 196 assertion in Dialog when moving from VC++ 6.0 to VS2017

$
0
0

Debug Assertion Failed!

Program: C:\WINDOWS\SYSTEM32\mfc140d.dll

File:

d:\agent\_work3\s\src\vctools\vc7libs\ship\atlmfc\src\mfc\appcore.cpp

Line: 196

For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts.

(Press Retry to debug the application)  

I have an app developed in VC++ 6.0 , Windows XP x32 and I want to migrate to VS 2017, Windows 10 x64

I tried registering TBarCode6.ocx using  TBarCode6.exe and regsvr32 - registration successful, but program crashes same way.

'Ares2017.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\mfc140d.dll'
'Ares2017.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\combase.dll'
'Ares2017.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\msvcp60.dll'
Debug Assertion Failed!

Program: C:\WINDOWS\SYSTEM32\mfc140d.dll
File: d:\agent\_work\3\s\src\vctools\vc7libs\ship\atlmfc\src\mfc\appcore.cpp
Line: 196

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.

(Press Retry to debug the application)
'Ares2017.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\WinTypes.dll'
'Ares2017.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\WinTypes.dll'

Visual Studio 2010 SP1 - Static Library -> Additional Include Directories Relative Path Not Working

$
0
0

I have created a Static Library and am attempting to include header files in another file location that are not inside my project file tree. For whatever reason the absolute path works just fine, but when I try to use the relative path instead, my static library is not importing those header files into the External Dependencies folder. 

The relative path works just fine if I created just a typical Win32 Windows application, but does not want to cooperate with the Static Library application type.

I have scoured the web searching for answers, my relative path is as follows:

..\..\..\library\

Viewing all 15302 articles
Browse latest View live


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