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

VssExpressWriter fails to add a folder non monitored files into restore point

$
0
0

I'm trying to use VSS Express Writer to include all the files in specific folder in the restore point when it is conducted which are crucial for my app to run.

Some of the files have extensions (mostly .txt) that is not automatically monitored (see https://docs.microsoft.com/en-us/windows/win32/sr/monitored-file-extensions for all auto monitored extensions).

So I've wrote a special vssWriter for those files (see https://docs.microsoft.com/en-us/windows/win32/vss/writers) and expected that the OS would call its requester which would add the files at the writer to the restore set..

After running my code, the writer created successfully and is visible from `vssadmin list writers`. However, the folder isn't kept once i go back to restore point (the files aren't there..)

Currently my flow goes as follow:

  1. Register using the following code (see below).
  2. Create system restore point.
  3. Delete my folder.
  4. Restart
  5. Restore my system.

Unfortunately, I dont get my folder back..

I've tried to summarize the code in the following block : 

int main()
{
    ::CoInitialize(NULL);

    createAndRegister();

}

int createAndRegister()
{
    CComPtr<IVssExpressWriter>                  spExpressWriter;
    CComPtr<IVssCreateExpressWriterMetadata>    spMetadata;

    CreateVssExpressWriter(&spExpressWriter);

    spExpressWriter->CreateMetadata(EXPRESS_WRITER_SAMPLE_GUID, L"Sample Express Writer", VSS_UT_USERDATA, 1, 0, 0, &spMetadata);

    PCWSTR  wszComponent = L"myExpressWriter";


    spMetadata->SetRestoreMethod(
        VSS_RME_RESTORE_AT_REBOOT, ////I've also tried it with different option of this enum
        NULL,
        NULL,                              
        VSS_WRE_NEVER,                     
        false),
        L"SetRestoreMethod failed");

    spMetadata->AddComponent(
        VSS_CT_FILEGROUP,
        NULL,
        wszComponent,
        wszComponent,
        NULL,
        0,
        false,
        false,
        false);   

    spMetadata->AddFilesToFileGroup(
        NULL,
        wszComponent,
        L"c:\\ProgramData\\myFolder",
        L"*.*",
        true,
        NULL,
        NULL),


    spExpressWriter->Register();
}

I am wondering if there is a need to implement a requester to add the files to restore properly (https://docs.microsoft.com/en-us/windows/win32/vss/requestors).

Perhaps anyone can tell me where did i go wrong in my flow ? 

Thanks 


CInternetSession - open files via Internet

$
0
0

 

In VS 6 I use that code:
C++:
       CInternetSession InternetSession;
        CStdioFile *pHttpFile;
        CFile File;
        try{
                m_sAktualizacja = "";
                pHttpFile = InternetSession.OpenURL("http://site.pl/data.xml");

                if(File.Open(pathTempDirectory+"\\data.xml", CFile::modeWrite | CFile::modeCreate))
                {
                        char pBuffer[200];
                        while(pHttpFile->ReadString(pBuffer, 199) != NULL)
                        {
                                CString strLinia1(pBuffer);}
                }
                pHttpFile->Close();
        }
        catch(CInternetException *e)
        {
                e->Delete();
        }


and everythink is OK. 
In VS 2005 the same code does not work. I changed it.
C++:

        CInternetSession InternetSession;
        CStdioFile *pHttpFile;
        CFile File;
        try{
                m_sAktualizacja = "";

                // Konwersja CString na LPTSTR
                CString theString("http://site.pl/data.xml");
                int sizeOfString = (theString.GetLength() + 1);
                LPTSTR url = new TCHAR[sizeOfString];
                _tcscpy_s(url, sizeOfString, theString);
                // Koniec
               
                pHttpFile = InternetSession.OpenURL(url);

                pathTempDirectory += "\\data.xml";
                CString pathTemp (pathTempDirectory);
                sizeOfString = (pathTempDirectory.GetLength() + 1);
                LPTSTR path = new TCHAR[sizeOfString];
                _tcscpy_s(path, sizeOfString, pathTemp);
               

                if(File.Open(path, CFile::modeWrite | CFile::modeCreate))
                { 
                        TCHAR pBuffer[200];
                        while(pHttpFile->ReadString(pBuffer, 200) != NULL)
                        {
                                CStringA strLinia1(pBuffer);            }
                }
                pHttpFile->Close();
        }
        catch(CInternetException *e)
        {
                e->Delete();
        }


but does not hit the correct data to the variable strLinia1


Thx for all help.

PS I don't want to turn on: Use Multi-Byte Character Set in project setting.

Unhandled exception in jscript9.dll in Windows Server 2016 when using MFC's CDHtmlDialog, after installing Microsoft update KB4507460

$
0
0

Hi.

An unhandled exception occurs in jscript9.dll in Windows Server 2016 when using MFC's CDHtmlDialog, after installing Microsoft update KB4507460.

I've attached a reproducible example here.


Windows Server 2016 (64-bit) Version 1607 (OS Build 14393.3085)

Visual Studio 2017 15.9.14

jscript9.dll mshtml.dll v11.0.14393.3085

Steps to reproduce:

1. Download and unzip HtmlBrowser.zip.

2. Open HtmlBrowser.sln in Visual Studio 2017.

3. Select the "Debug | x64" solution configuration.

4. Start debugging the HtmlBrowser project.

Notice a similar exception as follows:

Exception thrown at 0x00007FFCFB1D4C48 in HtmlBrowser.exe: Microsoft C++ exception: Js::JavascriptExceptionObject at memory location 0x0000008C78FB9EE0.

Call Stack:

     [External Code]    
     jscript9.dll!Js::JavascriptExceptionOperators::ThrowExceptionObjectInternal()    Unknown
     jscript9.dll!Js::JavascriptExceptionOperators::ThrowExceptionObject(class Js::JavascriptExceptionObject *,class Js::ScriptContext *,bool,void *)    Unknown
     jscript9.dll!Js::JavascriptExceptionOperators::Throw()    Unknown
     jscript9.dll!CJavascriptOperations::ThrowException()    Unknown
     mshtml.dll!CFastDOM::ThrowDOMError()    Unknown
     mshtml.dll!CFastDOM::CElement::Trampoline_querySelectorAll(void *,struct CallInfo,...)    Unknown
     jscript9.dll!amd64_CallFunction()    Unknown
     jscript9.dll!Js::JavascriptExternalFunction::ExternalFunctionThunk()    Unknown
     jscript9.dll!amd64_CallFunction()    Unknown
     jscript9.dll!Js::InterpreterStackFrame::Process(void)    Unknown
     jscript9.dll!Js::InterpreterStackFrame::InterpreterThunk<1>(class Js::JavascriptCallStackLayout *)    Unknown
     000001b9a8d10e73()    Unknown
     jscript9.dll!amd64_CallFunction()    Unknown
     jscript9.dll!Js::JavascriptFunction::CallFunction<1>()    Unknown
     jscript9.dll!Js::InterpreterStackFrame::OP_CallCommon<struct Js::OpLayoutDynamicProfile<struct Js::OpLayoutCallI_OneByte> >(struct Js::OpLayoutDynamicProfile<struct Js::OpLayoutCallI_OneByte> const *,class Js::RecyclableObject *,unsigned int)    Unknown
     jscript9.dll!Js::InterpreterStackFrame::Process(void)    Unknown
     jscript9.dll!Js::InterpreterStackFrame::OP_TryCatch()    Unknown
     jscript9.dll!Js::InterpreterStackFrame::Process(void)    Unknown
     jscript9.dll!Js::InterpreterStackFrame::OP_TryFinally()    Unknown
     jscript9.dll!Js::InterpreterStackFrame::Process(void)    Unknown
     jscript9.dll!Js::InterpreterStackFrame::InterpreterThunk<1>(class Js::JavascriptCallStackLayout *)    Unknown
     000001b9a8d10eb3()    Unknown
     jscript9.dll!amd64_CallFunction()    Unknown
     jscript9.dll!Js::InterpreterStackFrame::Process(void)    Unknown
     jscript9.dll!Js::InterpreterStackFrame::InterpreterThunk<1>(class Js::JavascriptCallStackLayout *)    Unknown
     000001b9a8d10ec3()    Unknown
     jscript9.dll!amd64_CallFunction()    Unknown
     jscript9.dll!Js::JavascriptFunction::CallFunction<1>()    Unknown
     jscript9.dll!Js::InterpreterStackFrame::OP_CallCommon<struct Js::OpLayoutDynamicProfile<struct Js::OpLayoutCallI_OneByte> >(struct Js::OpLayoutDynamicProfile<struct Js::OpLayoutCallI_OneByte> const *,class Js::RecyclableObject *,unsigned int)    Unknown
     jscript9.dll!Js::InterpreterStackFrame::Process(void)    Unknown
     jscript9.dll!Js::InterpreterStackFrame::InterpreterThunk<1>(class Js::JavascriptCallStackLayout *)    Unknown
     000001b9a8d10efb()    Unknown
     jscript9.dll!amd64_CallFunction()    Unknown
     jscript9.dll!Js::JavascriptFunction::CallFunction<1>()    Unknown
     jscript9.dll!Js::InterpreterStackFrame::OP_CallCommon<struct Js::OpLayoutDynamicProfile<struct Js::OpLayoutCallI> >(struct Js::OpLayoutDynamicProfile<struct Js::OpLayoutCallI> const *,class Js::RecyclableObject *,unsigned int)    Unknown
     jscript9.dll!Js::InterpreterStackFrame::OP_ProfiledReturnTypeCallI<struct Js::OpLayoutCallI>(struct Js::OpLayoutDynamicProfile<struct Js::OpLayoutCallI> const *,unsigned int)    Unknown
     jscript9.dll!Js::InterpreterStackFrame::Process(void)    Unknown
     jscript9.dll!Js::InterpreterStackFrame::InterpreterThunk<1>(class Js::JavascriptCallStackLayout *)    Unknown
     000001b9a8d10fbb()    Unknown
     jscript9.dll!amd64_CallFunction()    Unknown
     jscript9.dll!Js::InterpreterStackFrame::Process(void)    Unknown
     jscript9.dll!Js::InterpreterStackFrame::InterpreterThunk<1>(class Js::JavascriptCallStackLayout *)    Unknown
     000001b9a8d10fc3()    Unknown
     jscript9.dll!amd64_CallFunction()    Unknown
     jscript9.dll!Js::JavascriptFunction::CallFunction<1>()    Unknown
     jscript9.dll!Js::JavascriptFunction::CallRootFunctionInternal()    Unknown
     jscript9.dll!Js::JavascriptFunction::CallRootFunction()    Unknown
     jscript9.dll!ScriptSite::CallRootFunction()    Unknown
     jscript9.dll!ScriptSite::Execute()    Unknown
     jscript9.dll!ScriptEngine::ExecutePendingScripts()    Unknown
     jscript9.dll!ScriptEngine::ParseScriptTextCore()    Unknown
     jscript9.dll!ScriptEngine::ParseScriptText()    Unknown
     mshtml.dll!CActiveScriptHolder::ParseScriptText()    Unknown
     mshtml.dll!CJScript9Holder::ParseScriptText()    Unknown
     mshtml.dll!CScriptCollection::ParseScriptText()    Unknown
     mshtml.dll!CScriptData::CommitCode()    Unknown
     mshtml.dll!CScriptData::Execute()    Unknown
     mshtml.dll!CHtmScriptParseCtx::Execute()    Unknown
     mshtml.dll!CHtmParseBase::Execute()    Unknown
     mshtml.dll!CHtmPost::Broadcast()    Unknown
     mshtml.dll!CHtmPost::Exec()    Unknown
     mshtml.dll!CHtmPost::Run()    Unknown
     mshtml.dll!PostManExecute()    Unknown
     mshtml.dll!CPostManager::PostManOnTimer()    Unknown
     mshtml.dll!GlobalWndOnMethodCall(void)    Unknown
     mshtml.dll!GlobalWndProc()    Unknown
     user32.dll!UserCallWinProcCheckWow()    Unknown
     user32.dll!CallWindowProcW()    Unknown>    mfc140ud.dll!_AfxActivationWndProc(HWND__ * hWnd, unsigned int nMsg, unsigned __int64 wParam, __int64 lParam) Line 478    C++
     user32.dll!UserCallWinProcCheckWow()    Unknown
     user32.dll!DispatchMessageWorker()    Unknown
     mfc140ud.dll!AfxInternalPumpMessage() Line 183    C++
     mfc140ud.dll!CWinThread::PumpMessage() Line 900    C++
     mfc140ud.dll!AfxPumpMessage() Line 190    C++
     mfc140ud.dll!CWnd::RunModalLoop(unsigned long dwFlags) Line 4661    C++
     mfc140ud.dll!CWnd::CreateRunDlgIndirect(const DLGTEMPLATE * lpDialogTemplate, CWnd * pParentWnd, HINSTANCE__ * hInst) Line 470    C++
     mfc140ud.dll!CDialog::DoModal() Line 633    C++
     HtmlBrowser.exe!CHtmlBrowserApp::InitInstance() Line 73    C++
     [External Code]    
     HtmlBrowser.exe!wWinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, wchar_t * lpCmdLine, int nCmdShow) Line 26    C++
     [External Code]    

I'm also wondering how I can prevent the JavaScript error from crashing the desktop application?

Thank you.


How do I set up the MFC SDI Tab view?

$
0
0
It succeeded in creating MFC application projects with SDI (CFormVirew -- Basic Class) and creating multi-view windows such as MDI.

But what I want to do is not the format in which a new window is created, but the way it opens in tab format. Is there no way?

I must do so.

Error in ShowWindow(SW_SHOW)

$
0
0

 Hi, I am working with an MFC application and modeless dialogs.  My code must certainly have one or more classes derived from CDialog(Ex) that are being used.  In the example I gave CModeless is such a class.

 I don't understand why it doesn't recognize TCB_MENUES although I introduced it at the beginning of the program #include "Tcbres.h" in which defines #define TCB_MENUES 103 ?


Expand to open folder option not working in Windows 10 version 1703

$
0
0

As part of our application, we are using Shell Namespace extension to create our folder view and interacting with windows explorer using interfaces like IShellFolder/IShellView/IEnumIDList/IContextMenu.

We are facing few issues after few windows updates versions as below :- 

1. For our application, we enabled "Expand to open folder" option, and while clicking on a folder from our application, left navigation tree is not expanding. 
  a)  when folder is clicked on right pane ( the corresponding folder on left pane does not expand)
  b)  when folder is clicked in left pane (  this works) 

We are facing this issue since Windows 10 version 1703. 
For earlier versions of the Windows 10( Build 1511, 1607), and  Windows 7/Windows XP, The folder on left/navigation pane   expands on  double click of folder on right pane.

Issue 2 : From our application, while enabling the toolbar(Press ALT Key), We are able to see File/Edit/View Menus but Help is missing from the Toolbar. 
We are facing this issue after Windows 10 version 1511. For Windows 10 Build 1511, It was showing Help Menu, But for the later versions, this menu option is missing from the toolbar. This is also working fine for early OS versions like Windows 7/XP.   

So it seems, for explorer process, from build 1703(and 1607) onwards, there had been changes in windows explorer. 
Can you please assist if some shell interface has been changed which we needed to take care for our application to address these issues for Windows 10. 

Can someone help us in resolving the above issues? Thanks in advance!

Thanks,

Ramakrishna

  

Starting https connection using winhttp API with different URL address and SNI name.

$
0
0

Hi, 

I'm using winHttpConnect in order to establish an https connection between my windows agent and a remote server whose URL is appliance1.com and listen on SNI appliance_api.

However, it seems like winHttpConnect only accept pswzServerName as an input, and it used to set both SNI and the server URL. 

In low level APIs such as openSSL, it's easy to differentiate the names : 

OpenSSL s_client -servername my_appliance -connect 192.0.2.4:443

OpenSSL s_client -servername my_appliance -connect my_appliance.com:443

Is there any option to do so in winhttp ? 

thanks,

Lot of Unnecessary Visual Studio Rebuilds - Tracking Log problem?

$
0
0

Hi - I'm getting an awful lot of unnecessary Visual Studio (2017) rebuilds.  Mine is a big Visual C++ project and all these builds are hitting my productivity badly so all help much appreciated.

I can't detect a pattern to the problem.  My perception is that sometimes it rebuilds practically every file when I've just changed one .cpp file.  Sometimes after a full build, if I hit build again, it will rebuild loads more files.  But sometimes it doesn't rebuild anything because it recognises that everything is up-to-date.

When this happened yet again just now (loads of files being rebuilt for no reason that I could see), I stopped the build and clicked on Tools -> Options. I chose Projects and Solutions -> Build and Run and selected Diagnostic in “MSbuild project build log file verbosity”.  I then restarted the build, waited a while, and checked the log file.  It had more than 10 pages filled with lines like this:

                     <source file>.cpp will be compiled because it was not found in the tracking log. (TaskId:28)


Anyone got any suggestions what the problem could be?


Simon


CTreeCtrl context menu and full row select

$
0
0
Hi All,

I have my own tree control derived from CTreeCtrl which handles context menu (ON_WM_CONTEXTMENU).
This is hosted inside a CDockablePane and all works well, right click on a node and you get a context menu etc.

However if I bind it to a tree control on a dialog via DDX_Control when I right click I do not get a context menu.
Additionally if right click changes the selection, when you release the right button the selection then flicks back to the previous selection.

The call to my OnContextMenu() is not been invoked from what I can tell in the dialog case.

Any ideas what is trapping/re-directing my message? There are no handlers in the dialog either!

Note if I double right click I do get a context menu!

Lastly TVS_FULLROWSELECT does not work when I specify it in the style parameters for creating the control that is in the CDockable pane, but just fine on a dialog!

Thanks

Intermediate Folder is re-created even after deleting

$
0
0
I have a VS 2015 CPP project. I have set the Visual Studio Intermediate directory (Project properties -> General -> Intermediate directory) to a custom folder. I use a cmd file for building the project. After building I delete the custom intermediate folder using command in the cmd file. When I execute the batch file, the build is completed and the custom folder is deleted successfully. However it is seen that the folder is re-created after waiting for some time...anyone has some idea what is the issue here?

How to do a toolbar in win32?

$
0
0

I have this program:


which has a toolbar at the top. Its using MFC CToolBar to do the toolbar. Does anyone know of a tutorial, helper code/classes or other information on how I can do a similar looking toolbar but using plain win32 API with no MFC at all? (the program I want to add the toolbar to is unrelated to the above program, I am using the screenshot as an example of the style of toolbar I want to replicate)

LNK2019 errors suddenly popping up

$
0
0

I have made a Windows desktop program in C Winapi with Microsoft Visual C++ 2010, which I use from time to time, and to which I now and then add some new functionalities. A few days ago the program suddenly wouldn’t open when I tried to start it. I found this strange, because I couldn’t remember to have compiled the program with any new code since last time I used it. I then went into the source code, and when building it, got a long list of LNK2019 errors. I googled each of them, and fixed the issues by doing the recommendations. Most of them were fixed by adding some libraries to Project properties > Configuration properties > Linker > Input > Additional dependencies. I added User32.lib, Gdi32.lib, Advapi32.lib and Shell32.lib. 

There is, however, one error I am not able to fix, and which is related to “tmainCRTStartup”.  I therefore still get the following error message:

1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library

1>LIBCMTD.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup

fatal error LNK1120: 1 unresolved externals

I believe I have tried all the recommendations on the internet, but has not been able to resolve the issue. I therefore hope that somebody could help me with this.

Lately I have added some code for playing with a midi keyboard, like “midiInStart”. It is said that this requires the header file “mmeapi.h”, but which I don’t have available, and which I neither know where to download. Yet my program has been working for a long time without it.

I am very puzzled how all these errors suddenly can pop up, after the program has been working fine for a long time. I wonder what’s the reason for this. Great if someone could give an explanation.

Thanks in advance.

Shell functions in Windows Server Core/Nano

$
0
0

Hi all,

we are attempting to build some of our existing projects so they can run on Windows Server Core and Nano. We've addedWINAPI_FAMILY=WINAPI_FAMILY_SERVER to the pre-processor definitions for the relevant projects. We are getting quite a few compiler errors. A lot of the errors are related to file/directory type functions that are found in the SDK shell libraries. Functions such as SHCreateDirectroyEx, PathIsRoot, GetShortPathName, SHFileOperation, etc.

Why are these functions only available for the desktop ?

Or is setting WINAPI_FAMILY=WINAPI_FAMILY_SERVER the wrong thing to do to compile for Windows Server Core/Nano ?

Anthony


How to set the property sheet inactive border color

$
0
0

Dear Sir,

    I am trying to set the property sheet border color. If I change the color corrresponding to one of COLOR_3DFACE or COLOR_INACTIVEBORDER(i am not ure which of the two) then the desired element color changes with the undesired side effect of changing all the window colors on the system. I have tried OnCtlColor with no luck. I have allready googled on the subject and have not found an answer.

Regards,

Ramesh D.



How to optimize the code snippet which has several calls to find method using map?

$
0
0

Hello All,

I wrote a functionality to read files and load them into the map (m_fileParams).

Then I am searching the specific keys in the map container using "find". Here using "find" I am searching different keys. 

My code is working fine. But I wanted to know how best I can optimize the code?

In several places I have used "find" to search the key in the map. Is there any way I can write generic method?

"m_fileParams" is declared like as shown below in the .h file:

std::map<std::wstring, std::wstring> m_fileParams;

below is the .cpp file:

bool McEMRMgr::ReadFile()
{
IOperation* pFileReader = new McFileReader();
std::map<std::wstring, std::wstring> mapFileReaderResponse;
if(pFileReader)
{
std::wstring strVendor, wstrFileLocation, wstrRegLocation;
std::wstring FileType, regType;

auto manufacSearchValue = m_fileParams.find(VENDOR);
if (manufacSearchValue != m_fileParams.end())
{
strVendor.assign(manufacSearchValue->second);
transform(
strVendor.begin(), strVendor.end(),
strVendor.begin(),
towlower);

}
else
{
strVendor.assign(L"default");
FileType.assign(L".File");
regType.assign(L".registry");
}
auto emailSearchValue = m_fileParams.find(L"email_locations." + strVendor + L".type" + FileType);
if (emailSearchValue != m_fileParams.end())

if (emailSearchValue->second.compare(L"File") == 0)
{
auto FileSearchPath = m_fileParams.find(L"email_locations." + strVendor + L".paths" + FileType);
wstrFileLocation = FileSearchPath->second;
}
}


emailSearchValue = m_fileParams.find(L"email_locations." + strVendor + L".type" + regType);
if (emailSearchValue->second.compare(L"registry") == 0)
{
auto regSearchPath = m_fileParams.find(L"email_locations." + strVendor + L".paths" + regType);
wstrRegLocation = regSearchPath->second;
}
}
if (wstrFileLocation.length() != 0)
{
std::wstring oemFolderPath;
auto oemSearchType = m_fileParams.find(L"oem_info_folder");
if (oemSearchType != m_fileParams.end())
{
oemFolderPath.assign(oemSearchType->second);
}
else
{
oemFolderPath.assign(OEM_FOLDER_DEFAULT_PATH);
}
std::wstring oemPathPublicKey(oemFolderPath), oemPathSessionKey(oemFolderPath), oemPathUserChoices(oemFolderPath);
oemPathPublicKey.append(PUBLIC_KEY_File);
oemPathSessionKey.append(SESSION_KEY_File);
oemPathUserChoices.append(USERCHOICES_File);
pFileReader->SetParams((wchar_t*)oemPathPublicKey.c_str(), L"File");
pFileReader->Execute();
pFileReader->SetParams((wchar_t*)oemPathSessionKey.c_str(), L"File");
pFileReader->Execute();
pFileReader->SetParams((wchar_t*)oemPathUserChoices.c_str(), L"File");
pFileReader->Execute();

wchar_t* ptrWStr;
wchar_t* buffer;
ptrWStr = wcstok_s((wchar_t*)wstrFileLocation.c_str(), L" ", &buffer);
while (ptrWStr != NULL)
{
pFileReader->SetParams(ptrWStr, L"File");
pFileReader->Execute();
mapFileReaderResponse = pFileReader->GetResponse();
for (std::map<std::wstring, std::wstring>::iterator it = mapFileReaderResponse.begin(); it != mapFileReaderResponse.end(); ++it)
{
m_fileParams.insert({ it->first, it->second });
}
ptrWStr = wcstok_s(nullptr, L" ", &buffer);
}

if (mapFileReaderResponse.size() != 0)
{
m_cJobState.eFileStatus = OperationState::Success;
}
else
{
m_cJobState.eFileStatus = OperationState::Failed;
}
}

if (wstrRegLocation.length() != 0)

pFileReader->SetParams((wchar_t*)wstrRegLocation.c_str(), L"registry");
pFileReader->Execute();
mapFileReaderResponse = pFileReader->GetResponse();
for (std::map<std::wstring, std::wstring>::iterator it = mapFileReaderResponse.begin(); it != mapFileReaderResponse.end(); ++it)
{
m_fileParams.insert({ it->first, it->second });
}
}
auto emailSearchType = m_fileParams.find(L"email");
std::wstring emailValue = emailSearchType->second;
if (emailValue.length() > 0)
{
MakeCopyofEmailToHKLM(emailValue);
}
else
{
}

delete pFileReader;
}

return true;
}

Someone please help me by providing your review comments.

Thanks in advance.


Changing MFC property sheet look

$
0
0

I have the following code which does not show my property sheet in the OutlookBar Style.

         AppPropSheet derives from CMFCPropertySheet
        CRunJobPage and CCreateJobPage Derives from CMFCPropertyPage

        AppPropSheet sht(_T("Backup"));

         CRunJobPage runjobpg;
         CCreateJobPage crjobpg;
                sht.AddPage(&crjobpg);
        sht.AddPage(&runjobpg);
      
        sht.m_shtSelImages.Create(IDB_BITMAP28, 32, 1, RGB(128, 128, 128));
        sht.SetIconsList(sht.m_shtSelImages.m_hImageList);
        sht.SetLook(CMFCPropertySheet::PropSheetLook_OutlookBar, 32);
        
        sht.m_psh.dwFlags |= PSH_NOAPPLYNOW;
       sht.DoModal();

Regards,

Ramesh D

The snippet below should not compile according to [dcl.enum]/7 in the C++ Standard.

$
0
0

The following code

#include <iostream>
#include <typeinfo>

enum E {
	a,
	b = 0x7FFFFFFFFFFFFFFF
};

int main()
{
	std::cout << "sizeof(0x7FFFFFFFFFFFFFFF) " << sizeof(0x7FFFFFFFFFFFFFFF) << '\n';
	std::cout << "sizeof(enum E) " << sizeof(enum E) << '\n';
	std::cout << "sizeof(E underlying type) " << sizeof(std::underlying_type<E>::type) << '\n';
}

prints

sizeof(0x7FFFFFFFFFFFFFFF) 8
sizeof(enum E) 4
sizeof(E underlying type) 4 

But the code should not compile according to [dcl.enum]/7 which says (emphases are mine):

For an enumeration whose underlying type is not fixed, the underlying type is an integral typethat can represent all the enumerator values defined in the enumeration.
 
If no integral type can represent all the enumerator values, the enumeration is ill-formed.
 
It is implementation-defined which integral type is used as the underlying type except that the underlying type shall not be larger than int unless the value of an enumerator cannot fit in an int or unsigned int.
 
If the enumerator-list is empty, the underlying type is as if the enumeration had a single enumerator with value 0.

PS: The compiler just emits a warning (C4309) for the initialization.

b = 0x7FFFFFFFFFFFFFFF


What redistributable for Visual C++ 2019?

$
0
0

We are shipping binaries built with Visual C++ 2019 (latest 16.2.2 version).

These binaries are built with /MD (to use the CRT dlls).

They are built with the "Windows SDK version" set to "10.0 (latest installed version)" and the "Platform toolset" set to "Visual Studio 2019 (v142)"

For the linker options we set the "minimum required version" to the default.

In our code we set _WIN32_WINNT to 0x0601. (for Windows 7). We are not using MFC or ATL.

I know that Windows ships certain CRT dlls (ucrtbase.dll for example) but can anyone tell me (based on the settings and things above whether the versions of Windows we target do or don't include the CRT dlls, which dlls are or aren't included with those versions of Windows and which, if any, CRT redistributable we should be shipping and installing to ensure our users have all the right dlls?

Can I remove the pointer variable with normal variable in the function?

$
0
0

Hello All,

I wrote a functionality to read files and load them into the map (m_fileParams).

Then I am searching the specific keys in the map container using "find". Here using "find" I am searching different keys. 

Can I replace the below pointer variable with normal variable?

IOperation* pFileReader = new McFileReader();

with 

McFileReader fileReader;

My code is working fine. But I wanted to know how best I can optimize the code?

In several places I have used "find" to search the key in the map. Is there any way I can write generic method?

"m_fileParams" is declared like as shown below in the .h file:

std::map<std::wstring, std::wstring> m_fileParams;

below is the .cpp file:

bool McEMRMgr::ReadFile()
{
IOperation* pFileReader = new McFileReader();
std::map<std::wstring, std::wstring> mapFileReaderResponse;
if(pFileReader)
{
std::wstring strVendor, wstrFileLocation, wstrRegLocation;
std::wstring FileType, regType;

auto manufacSearchValue = m_fileParams.find(VENDOR);
if (manufacSearchValue != m_fileParams.end())
{
strVendor.assign(manufacSearchValue->second);
transform(
strVendor.begin(), strVendor.end(),
strVendor.begin(),
towlower);

}
else
{
strVendor.assign(L"default");
FileType.assign(L".File");
regType.assign(L".registry");
}
auto emailSearchValue = m_fileParams.find(L"email_locations." + strVendor + L".type" + FileType);
if (emailSearchValue != m_fileParams.end())

if (emailSearchValue->second.compare(L"File") == 0)
{
auto FileSearchPath = m_fileParams.find(L"email_locations." + strVendor + L".paths" + FileType);
wstrFileLocation = FileSearchPath->second;
}
}


emailSearchValue = m_fileParams.find(L"email_locations." + strVendor + L".type" + regType);
if (emailSearchValue->second.compare(L"registry") == 0)
{
auto regSearchPath = m_fileParams.find(L"email_locations." + strVendor + L".paths" + regType);
wstrRegLocation = regSearchPath->second;
}
}
if (wstrFileLocation.length() != 0)
{
std::wstring oemFolderPath;
auto oemSearchType = m_fileParams.find(L"oem_info_folder");
if (oemSearchType != m_fileParams.end())
{
oemFolderPath.assign(oemSearchType->second);
}
else
{
oemFolderPath.assign(OEM_FOLDER_DEFAULT_PATH);
}
std::wstring oemPathPublicKey(oemFolderPath), oemPathSessionKey(oemFolderPath), oemPathUserChoices(oemFolderPath);
oemPathPublicKey.append(PUBLIC_KEY_File);
oemPathSessionKey.append(SESSION_KEY_File);
oemPathUserChoices.append(USERCHOICES_File);
pFileReader->SetParams((wchar_t*)oemPathPublicKey.c_str(), L"File");
pFileReader->Execute();
pFileReader->SetParams((wchar_t*)oemPathSessionKey.c_str(), L"File");
pFileReader->Execute();
pFileReader->SetParams((wchar_t*)oemPathUserChoices.c_str(), L"File");
pFileReader->Execute();

wchar_t* ptrWStr;
wchar_t* buffer;
ptrWStr = wcstok_s((wchar_t*)wstrFileLocation.c_str(), L" ", &buffer);
while (ptrWStr != NULL)
{
pFileReader->SetParams(ptrWStr, L"File");
pFileReader->Execute();
mapFileReaderResponse = pFileReader->GetResponse();
for (std::map<std::wstring, std::wstring>::iterator it = mapFileReaderResponse.begin(); it != mapFileReaderResponse.end(); ++it)
{
m_fileParams.insert({ it->first, it->second });
}
ptrWStr = wcstok_s(nullptr, L" ", &buffer);
}

if (mapFileReaderResponse.size() != 0)
{
m_cJobState.eFileStatus = OperationState::Success;
}
else
{
m_cJobState.eFileStatus = OperationState::Failed;
}
}

if (wstrRegLocation.length() != 0)

pFileReader->SetParams((wchar_t*)wstrRegLocation.c_str(), L"registry");
pFileReader->Execute();
mapFileReaderResponse = pFileReader->GetResponse();
for (std::map<std::wstring, std::wstring>::iterator it = mapFileReaderResponse.begin(); it != mapFileReaderResponse.end(); ++it)
{
m_fileParams.insert({ it->first, it->second });
}
}
auto emailSearchType = m_fileParams.find(L"email");
std::wstring emailValue = emailSearchType->second;
if (emailValue.length() > 0)
{
MakeCopyofEmailToHKLM(emailValue);
}
else
{
}

delete pFileReader;
}

return true;
}

Someone please help me by providing your review comments.

Thanks in advance.



How to write a generic function to insert elements into the map container using C++?

$
0
0

Hello All,

I am inserting elements into the map container. For this I am using the same statements multiple times in the below function. Is there any way I can write a generic function for this? So that even at the later point of time, when required, I can insert new elements.

bool EMRMgr::GetParams()
{
EmIOStruct emIOstructObj;
WCHAR szValue[MAX_PATH] = { 0 };
DWORD dwDataSize = sizeof(szValue) / sizeof(WCHAR);
long lRes = 0;
McStorageType mcStorageTypeObj = McStorageType::eRegistry;
std::wstring value;

// First time I am using the below statements to insert elements into the map container
mcIOstructObj.lpszValueName = (LPWSTR)ER_ID;
memset(szValue, 0, MAX_PATH);
mcIOstructObj.lpData = (LPBYTE)&szValue[0];
lRes = m_cIOManager.ReadValue(mcStorageTypeObj, mcIOstructObj);
value.clear();
if ((LPWSTR)mcIOstructObj.lpData == nullptr)
{
value.assign(L"");
}
else
{
value.assign((LPWSTR)mcIOstructObj.lpData);
}

m_fileParams.insert({ (std::wstring) ER_ID, value });

// Second time I am using the below statements to insert elements into the map container


mcIOstructObj.lpszValueName = (LPWSTR)CPS;
memset(szValue, 0, MAX_PATH);
mcIOstructObj.lpData = (LPBYTE)&szValue[0];
lRes = m_cIOManager.ReadValue(mcStorageTypeObj, mcIOstructObj);
value.clear();
if ((LPWSTR)mcIOstructObj.lpData == nullptr)
{
value.assign(L"");
}
else
{
value.assign((LPWSTR)mcIOstructObj.lpData);
}
m_fileParams.insert({ (std::wstring) CPS, value });

return true;
}

could anyone please help me on this?

Thanks in advance.

Viewing all 15302 articles
Browse latest View live


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