I'm trying to make this console program and it has to resize the console itself to put the text I want in it, so I used this method to resize it:
#include <windows.h>
using namespace std;
int main ()
{
HWND console = GetConsoleWindow();
RECT r;
GetWindowRect(console, &r); //stores the console's current dimensions
MoveWindow(console, r.left, r.top, 775, 575, TRUE); // 775 width, 575 height
}
It works perfectly with the rest of my code. The only problem is that when I send my program to a friend it says "MSVCP140.dll" is missing in his PC.
So to fix this what I always do is change in Visual Studio's Project settings from "Use Standard Windows Libraries" to "Use Static MFC Library" and that way it won't ask for "MSVCP140.dll". The only problem here is that when I set it to Use Static MFC Library it throws this error:
Unresolved external symbol _imp_GetWindowRect
Unresolved external symbol _imp_MoveWindow
If I remove the Console resize command from above, it will work no problem. So the problem is basically that if I use the Console Resize I have to use Standard Library and if I don't I can use MFC Library. but I need to use the Console resize with the MFC so it doesn't ask for a .dll to open on other's computer.
I'm going crazy over here. Any ideas/thoughts?
I believe you're changing the wrong setting. If you're not using MFC, leave the "Use of MFC" option at "Use Standard Windows Libraries".
Instead, look under "C/C++ / Code Generation" and change the "Runtime Library" option from "Multi-threaded DLL" to "Multi-threaded"
Similarly, in Debug mode, you'd switch from "Multi-threaded Debug DLL" to just "Multi-threaded Debug"
or
You could have your friend download & install the Visual C++ Redistributable for Visual Studio 2015
Related
How can I debug the dynamic library conveniently and quickly in Visual Studio 2022?
If Xenos injection is used, nothing is output (random process).
If it passes through the attached process, it does not enter any breakpoint (random process).
#include "pch.h"
#include <iostream>
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
std::system("ls>1.txt");
case DLL_PROCESS_ATTACH:
OutputDebugString(TEXT("INterdll"));
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
In Visual Studio 2022 you can debug your own library by attaching to the application which uses your library. When I usually develop C++ libraries, I create a separate project which called <MyLibrary>Tests and connect gtest library.
This way guarantees that your library will be under testing and when you'll run your tests, you could attach to this process.
To attach your codebase to the application, you have to use menu option Debug → Attach to Process...:
When you press it, you'll be able to find your application which is using your library currently.
And, as I understand on my last work place, the best way to debug your library is make your small GUI application with some buttons for testing. It's pretty enough to make a simple Python app to check it.
From Specify symbol (.pdb) and source files in the Visual Studio debugger (C#, C++, Visual Basic, F#), the quickest way to fix this is via the Modules Window in the Debugger:
Put a breakpoint after your call.LoadLibrary
Go to Debug->Windows->Modules in the menu bar to bring up the Modules window.
Search for your dll file in the list. In the Symbol Status column it should read "Cannot find or open the PDB file".
Right click the dll and choose Load Symbols from the context menu.
Point it to the correct pdb file.
The Symbol Status should now change to "Symbols Loaded".
You should now be able to step into functions from the dll and add breakpoints.
I have a Visual Studio 2013 C++ DLL project.
The build DLL works fine, except one point: There is a lack of interactive form which should open when DLL starts & it should be responsive to/from the DLL
I had referred to this link
I tried:
Right click on Project-> Select Add->Resource->Dialog
After that, a blank Dialog box appeared in the Visual Studio tab and it was listed in the Resources folder
I thought simply compiling the project would make the empty Dialog box display while running the DLL.
But even the empty Dialog box is not displayed when I run the DLL
Am I missing something here?
Also, would C++ be sufficient to add functionality to the form/Dialog? Or, any other language like C#?
(So that I may add event handling kind of functionality to that)
I suggest that you could use MFC to add functionality to the form/Dialog.
Here are the steps:
Create a MFC DLL named 'CTestDll', and select Regular DLL using shared MFC DLL
Then select Add->Resource->Dialog
Add code in CTestDll.cpp
#include "CTestDlg.h"
extern "C" __declspec(dllexport) void Show()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CTestDlg test;
test.DoModal();
}
Create a MFC App for testing. You could call it through the button click event.
void CMFCApplication3Dlg::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
typedef void (WINAPI *TESTDLL)();
HINSTANCE hInstance = LoadLibrary(_T("CTestDll.dll")); //
if (hInstance != NULL)
{
TESTDLL TestShow = (TESTDLL)GetProcAddress(hInstance, "Show");
if (TestShow != NULL)
{
TestShow();
}
FreeLibrary(hInstance);
}
}
I am attempting to migrate a Visual C++ 6.0 program (originally written on a Windows NT machine) to Visual C++ 2010 for use on my 64-bit Windows 7 PC. The program compiles fine but there is a runtime assertion failure which yeilds the following output in the debugger:
CoCreateInstance of OLE control {F9043C85-F6F2-101A-A3C9-08002B2F49FB}
failed.
Result code: 0x80040154
Is the control is properly registered?
Warning: Resource items and Win32 Z-order lists are out of sync. Tab
order may be not defined well.
Warning: CreateDlgControls failed during dialog init.
The failed assertion is on line 925 of occcont.cpp:
ASSERT(IsWindow(pTemp->m_hWnd));
I understand from http://dynamicsuser.net/forums/p/25968/140697.aspx that the Microsoft Common Dialog Control v6.0 might not be registered. I registered it with Regsrv32.exe and restarted windows but the error persists.
My goal is to tell whether this old program can work with new tools--not to actually rewrite the old program (though that will come later). Is it possible to make the old program run on my newer machine?
EDIT: Addition of the code which causes the assertion failure
BOOL CCameraSimulationApp::InitInstance()
{
AfxEnableControlContainer();
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
INITCOMMONCONTROLSEX InitCtrlEx;
InitCtrlEx.dwSize = sizeof(INITCOMMONCONTROLSEX);
InitCtrlEx.dwICC = ICC_PROGRESS_CLASS;
if (!InitCommonControlsEx(&InitCtrlEx))
{
printf("Common Controls failed to initialize");//debug
}
CCameraSimulationDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
...
0x80040154 is REGDB_E_CLASSNOTREG. That means that the class has not been registered.
{F9043C85-F6F2-101A-A3C9-08002B2F49FB} is the Commom Dialog Control.
So, it seems that that control is not registered. You attempted to register it but I'd guess that you registered the 64 bit version. You are likely compiling a 32 bit program and so need to register the 32 bit version.
regsvr32 C:\Windows\SysWOW64\ComDlg32.ocx
Make sure you do this whilst elevated. That said, I would expect the control to be registered out of the box.
Finally, it's 2015 now and you should not be using this control anymore. Try to wean yourself onto something more modern.
I'd also comment that there's no need for you to re-compile the program. To start with I'd concentrate on getting your existing executable to work on the new machine.
I'm currently linking to the >dynamic< libs in SFML but I have no idea how to add resources in Visual Studio 2013 Express C++. I've quite recently started out with C++, coming from C# where adding resources is as simple as drag-n-drop.
I know there's something with .rc files and headers, but I didn't find any guide on it. What I need to do is add the dll's so I don't have to manually paste them with the .exe and I also need to add .png's. Right now I'm loading them from a folder next to the executable, I don't wanna do that.
How do I do this?
You can just add an [.rc] file to the project.
An [.rc] file is a purely textual resource script that you can edit as text, or you can use various 3rd party resource editors (you don't need that for adding image resources, just check out the RC syntax).
Visual Studio Express lacks resource editors, but does support automatic recognition of, compilation of and linking of resources.
Example
Here's an example [.rc] file, just a single line, using a free icon that I just downloaded from the net:
100 ICON "resources\\Bad-Blood-Yolks-Grin.ico"
Corresponding C++ source code, presenting the icon in a message box:
#undef UNICODE
#define UNICODE
#include <windows.h>
auto main() -> int
{
MSGBOXPARAMS params = {sizeof( params )};
params.hInstance = GetModuleHandle( nullptr );
params.lpszText = L"Click OK to dismiss this box.";
params.lpszCaption = L"Καλὴ τύχη!"; // "Good luck!" in Greek.
params.dwStyle = MB_USERICON;
params.lpszIcon = MAKEINTRESOURCE( 100 );
MessageBoxIndirect( ¶ms );
}
Result:
All done in Visual C++ Express for Desktop 2013, or whatever it calls itself. :-)
In order to synchronize identifiers between resource script and C or C++ code it's common to include a header. The resource compiler understands the most basic C preprocessor directives.
Oh, also, I added the [.rc] file as just a text file. Visual Studio Express reacts to the renaming, "rc" file extension, by popping up a warning box that it isn't supported. Just ignore the box, and to edit the file right-click and choose text editor.
In my Qt 4.7.4 x64 C++ app I'm building in Qt Creator 2.5.0, I want to give full access to everyone for a file. I'm using QFile::setPermissions, which I believe works fine for Mac and Linux, but it doesn't work for Windows. According to Qt setPermissions not setting permisions, I should use
SetNamedSecurityInfoA("C:\file.txt", SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, NULL, NULL, NULL, NULL);
But I don't know what to #include to make it work. I tried:
#ifdef Q_WS_WIN
#include "Windows.h"
#endif
based on what I found here. But when I compile, I get C3861: 'SetNamedSecurityInfo': identifier not found (among some other new errors).
When I mouse over my #include "Windows.h", I get the tooltip: C:\Program Files\Microsoft SDKs\Windows\v7.0\include\Windows.h, and I can press F2 and jump to that file. We have other files in our project that include that same Windows.h, and they compile fine.
How do I set file permissions on Windows for everyone to read/write? If SetNamedSecurityInfo is what I want (I guess SetNamedSecurityInfoW in my case since my users may be running OS's in any language), what do I #include to be able to use it? Better yet, how do I figure out what to #include, so I know for next time I need to use the Windows API?
SetNamedSecurityInfo
Header
Aclapi.h
Library
Advapi32.lib
DLL
Advapi32.dll
A quick search on Google would probably have had this page among it top hits. There you can see which header file and library you need.