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

How to make edit control as not editable without using setreadonly function?

$
0
0

Hi,

How to make edit control  as not editable without using setreadonly function?


Cross platform console app structure - Separate projects for windows and linux?

$
0
0

When using CMake to write a cross-platform application, I have one codebase, and then Cmake compiles the codebase for the target architecture when i tell it to compile.  

I'm new to VS for C++, but it looks like the "recommended" approach to making a cross-platform application is two create one project for each OS.  In each such project, you can have configurations for different architectures, but you basically need at least 2 projects.  If you want to share code, you need a third project using the "shared items" project type.   Is this correct? 


C++ 2015 redistributable x64 0 80240017

$
0
0

hi 

I try to setup C++ 2015 redistributable x64 but its failed with 0*80240017!! the log file :

[0824:1228][2018-12-05T19:27:03]i001: Burn v3.7.3813.0, Windows v6.3 (Build 9600: Service Pack 0), path: C:\Users\Ali\Downloads\vc_redist.x64.exe, cmdline: ''
[0824:1228][2018-12-05T19:27:03]i000: Setting string variable 'WixBundleLog' to value 'C:\Users\Ali\AppData\Local\Temp\dd_vcredist_amd64_20181205192703.log'
[0824:1228][2018-12-05T19:27:03]i000: Setting string variable 'WixBundleOriginalSource' to value 'C:\Users\Ali\Downloads\vc_redist.x64.exe'
[0824:1228][2018-12-05T19:27:03]i000: Setting string variable 'WixBundleOriginalSourceFolder' to value 'C:\Users\Ali\Downloads\'
[0824:1228][2018-12-05T19:27:03]i000: Setting string variable 'WixBundleName' to value 'Microsoft Visual C++ 2015 Redistributable (x64) - 14.0.23918'
[0824:1228][2018-12-05T19:27:04]i100: Detect begin, 10 packages
[0824:1228][2018-12-05T19:27:04]i000: File search: windows_uCRT_DetectKey, did not find path: C:\Windows\system32\ucrtbase.dll
[0824:1228][2018-12-05T19:27:04]i000: File search: windows_uCRT_DetectKeyExists, did not find path: C:\Windows\system32\ucrtbase.dll
[0824:1228][2018-12-05T19:27:04]i000: Setting numeric variable 'windows_uCRT_DetectKeyExists' to value 0
[0824:1228][2018-12-05T19:27:04]i052: Condition '(VersionNT = v6.3 AND NOT VersionNT64) AND (windows_uCRT_DetectKeyExists AND windows_uCRT_DetectKey >= v10.0.10240.0)' evaluates to false.
[0824:1228][2018-12-05T19:27:04]i052: Condition '(VersionNT = v6.3 AND VersionNT64) AND (windows_uCRT_DetectKeyExists AND windows_uCRT_DetectKey >= v10.0.10240.0)' evaluates to false.
[0824:1228][2018-12-05T19:27:04]i052: Condition '(VersionNT = v6.2 AND NOT VersionNT64) AND (windows_uCRT_DetectKeyExists AND windows_uCRT_DetectKey >= v10.0.10240.0)' evaluates to false.
[0824:1228][2018-12-05T19:27:04]i052: Condition '(VersionNT = v6.2 AND VersionNT64) AND (windows_uCRT_DetectKeyExists AND windows_uCRT_DetectKey >= v10.0.10240.0)' evaluates to false.
[0824:1228][2018-12-05T19:27:04]i052: Condition '(VersionNT = v6.1 AND NOT VersionNT64) AND (windows_uCRT_DetectKeyExists AND windows_uCRT_DetectKey >= v10.0.10240.0)' evaluates to false.
[0824:1228][2018-12-05T19:27:04]i052: Condition '(VersionNT = v6.1 AND VersionNT64) AND (windows_uCRT_DetectKeyExists AND windows_uCRT_DetectKey >= v10.0.10240.0)' evaluates to false.
[0824:1228][2018-12-05T19:27:04]i052: Condition '(VersionNT = v6.0 AND NOT VersionNT64) AND (windows_uCRT_DetectKeyExists AND windows_uCRT_DetectKey >= v10.0.10240.0)' evaluates to false.
[0824:1228][2018-12-05T19:27:04]i052: Condition '(VersionNT = v6.0 AND VersionNT64) AND (windows_uCRT_DetectKeyExists AND windows_uCRT_DetectKey >= v10.0.10240.0)' evaluates to false.
[0824:1228][2018-12-05T19:27:04]i101: Detected package: vcRuntimeMinimum_x64, state: Absent, cached: None
[0824:1228][2018-12-05T19:27:04]i101: Detected package: vcRuntimeAdditional_x64, state: Absent, cached: None
[0824:1228][2018-12-05T19:27:04]i101: Detected package: Windows81_x86, state: Absent, cached: None
[0824:1228][2018-12-05T19:27:04]i101: Detected package: Windows81_x64, state: Absent, cached: None
[0824:1228][2018-12-05T19:27:04]i101: Detected package: Windows8_x86, state: Absent, cached: None
[0824:1228][2018-12-05T19:27:04]i101: Detected package: Windows8_x64, state: Absent, cached: None
[0824:1228][2018-12-05T19:27:04]i101: Detected package: Windows7_MSU_x86, state: Absent, cached: None
[0824:1228][2018-12-05T19:27:04]i101: Detected package: Windows7_MSU_x64, state: Absent, cached: None
[0824:1228][2018-12-05T19:27:04]i101: Detected package: WindowsVista_MSU_x86, state: Absent, cached: None
[0824:1228][2018-12-05T19:27:04]i101: Detected package: WindowsVista_MSU_x64, state: Absent, cached: None
[0824:1228][2018-12-05T19:27:04]i052: Condition 'VersionNT64 >= v6.0 OR (VersionNT64 = v5.2 AND ServicePackLevel >= 1)' evaluates to true.
[0824:1228][2018-12-05T19:27:04]i199: Detect complete, result: 0x0
[0824:1228][2018-12-05T19:27:16]i200: Plan begin, 10 packages, action: Install
[0824:1228][2018-12-05T19:27:16]i052: Condition '(VersionNT64)' evaluates to true.
[0824:1228][2018-12-05T19:27:16]i000: Setting string variable 'WixBundleRollbackLog_vcRuntimeMinimum_x64' to value 'C:\Users\Ali\AppData\Local\Temp\dd_vcredist_amd64_20181205192703_000_vcRuntimeMinimum_x64_rollback.log'
[0824:1228][2018-12-05T19:27:16]i000: Setting string variable 'WixBundleLog_vcRuntimeMinimum_x64' to value 'C:\Users\Ali\AppData\Local\Temp\dd_vcredist_amd64_20181205192703_000_vcRuntimeMinimum_x64.log'
[0824:1228][2018-12-05T19:27:16]i052: Condition '(VersionNT64)' evaluates to true.
[0824:1228][2018-12-05T19:27:16]i000: Setting string variable 'WixBundleRollbackLog_vcRuntimeAdditional_x64' to value 'C:\Users\Ali\AppData\Local\Temp\dd_vcredist_amd64_20181205192703_001_vcRuntimeAdditional_x64_rollback.log'
[0824:1228][2018-12-05T19:27:16]i000: Setting string variable 'WixBundleLog_vcRuntimeAdditional_x64' to value 'C:\Users\Ali\AppData\Local\Temp\dd_vcredist_amd64_20181205192703_001_vcRuntimeAdditional_x64.log'
[0824:1228][2018-12-05T19:27:16]i052: Condition 'VersionNT = v6.3 AND NOT VersionNT64' evaluates to false.
[0824:1228][2018-12-05T19:27:16]w321: Skipping dependency registration on package with no dependency providers: Windows81_x86
[0824:1228][2018-12-05T19:27:16]i052: Condition 'VersionNT = v6.3 AND VersionNT64' evaluates to true.
[0824:1228][2018-12-05T19:27:16]w321: Skipping dependency registration on package with no dependency providers: Windows81_x64
[0824:1228][2018-12-05T19:27:16]i052: Condition 'VersionNT = v6.2 AND NOT VersionNT64' evaluates to false.
[0824:1228][2018-12-05T19:27:16]w321: Skipping dependency registration on package with no dependency providers: Windows8_x86
[0824:1228][2018-12-05T19:27:16]i052: Condition 'VersionNT = v6.2 AND VersionNT64' evaluates to false.
[0824:1228][2018-12-05T19:27:16]w321: Skipping dependency registration on package with no dependency providers: Windows8_x64
[0824:1228][2018-12-05T19:27:16]i052: Condition 'VersionNT = v6.1 AND NOT VersionNT64' evaluates to false.
[0824:1228][2018-12-05T19:27:16]w321: Skipping dependency registration on package with no dependency providers: Windows7_MSU_x86
[0824:1228][2018-12-05T19:27:16]i052: Condition 'VersionNT = v6.1 AND VersionNT64' evaluates to false.
[0824:1228][2018-12-05T19:27:16]w321: Skipping dependency registration on package with no dependency providers: Windows7_MSU_x64
[0824:1228][2018-12-05T19:27:16]i052: Condition 'VersionNT = v6.0 AND NOT VersionNT64' evaluates to false.
[0824:1228][2018-12-05T19:27:16]w321: Skipping dependency registration on package with no dependency providers: WindowsVista_MSU_x86
[0824:1228][2018-12-05T19:27:16]i052: Condition 'VersionNT = v6.0 AND VersionNT64' evaluates to false.
[0824:1228][2018-12-05T19:27:16]w321: Skipping dependency registration on package with no dependency providers: WindowsVista_MSU_x64
[0824:1228][2018-12-05T19:27:16]i201: Planned package: vcRuntimeMinimum_x64, state: Absent, default requested: Present, ba requested: Present, execute: Install, rollback: Uninstall, cache: Yes, uncache: No, dependency: Register
[0824:1228][2018-12-05T19:27:16]i201: Planned package: vcRuntimeAdditional_x64, state: Absent, default requested: Present, ba requested: Present, execute: Install, rollback: Uninstall, cache: Yes, uncache: No, dependency: Register
[0824:1228][2018-12-05T19:27:16]i201: Planned package: Windows81_x86, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None
[0824:1228][2018-12-05T19:27:16]i201: Planned package: Windows81_x64, state: Absent, default requested: Present, ba requested: Present, execute: Install, rollback: Uninstall, cache: Yes, uncache: No, dependency: None
[0824:1228][2018-12-05T19:27:16]i201: Planned package: Windows8_x86, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None
[0824:1228][2018-12-05T19:27:16]i201: Planned package: Windows8_x64, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None
[0824:1228][2018-12-05T19:27:16]i201: Planned package: Windows7_MSU_x86, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None
[0824:1228][2018-12-05T19:27:16]i201: Planned package: Windows7_MSU_x64, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None
[0824:1228][2018-12-05T19:27:16]i201: Planned package: WindowsVista_MSU_x86, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None
[0824:1228][2018-12-05T19:27:16]i201: Planned package: WindowsVista_MSU_x64, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None
[0824:1228][2018-12-05T19:27:16]i299: Plan complete, result: 0x0
[0824:1228][2018-12-05T19:27:16]i300: Apply begin
[03A0:0728][2018-12-05T19:27:17]i360: Creating a system restore point.
[03A0:0728][2018-12-05T19:27:40]i361: Created a system restore point.
[03A0:0728][2018-12-05T19:27:40]i370: Session begin, registration key: SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{dab68466-3a7d-41a8-a5cf-415e3ff8ef71}, options: 0x7, disable resume: No
[03A0:0728][2018-12-05T19:27:40]i000: Caching bundle from: 'C:\Users\Ali\AppData\Local\Temp\{dab68466-3a7d-41a8-a5cf-415e3ff8ef71}\.be\VC_redist.x64.exe' to: 'C:\ProgramData\Package Cache\{dab68466-3a7d-41a8-a5cf-415e3ff8ef71}\VC_redist.x64.exe'
[03A0:0728][2018-12-05T19:27:40]i320: Registering bundle dependency provider: {dab68466-3a7d-41a8-a5cf-415e3ff8ef71}, version: 14.0.23918.0
[03A0:0728][2018-12-05T19:27:40]i371: Updating session, registration key: SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{dab68466-3a7d-41a8-a5cf-415e3ff8ef71}, resume: Active, restart initiated: No, disable resume: No
[03A0:05E0][2018-12-05T19:27:41]i304: Verified existing payload: vcRuntimeMinimum_x64 at path: C:\ProgramData\Package Cache\.unverified\vcRuntimeMinimum_x64.
[03A0:05E0][2018-12-05T19:27:41]i305: Verified acquired payload: vcRuntimeMinimum_x64 at path: C:\ProgramData\Package Cache\.unverified\vcRuntimeMinimum_x64, moving to: C:\ProgramData\Package Cache\{7B50D081-E670-3B43-A460-0E2CDB5CE984}v14.0.23918\packages\vcRuntimeMinimum_amd64\vc_runtimeMinimum_x64.msi.
[03A0:05E0][2018-12-05T19:27:41]i304: Verified existing payload: cab5046A8AB272BF37297BB7928664C9503 at path: C:\ProgramData\Package Cache\.unverified\cab5046A8AB272BF37297BB7928664C9503.
[03A0:05E0][2018-12-05T19:27:41]i305: Verified acquired payload: cab5046A8AB272BF37297BB7928664C9503 at path: C:\ProgramData\Package Cache\.unverified\cab5046A8AB272BF37297BB7928664C9503, moving to: C:\ProgramData\Package Cache\{7B50D081-E670-3B43-A460-0E2CDB5CE984}v14.0.23918\packages\vcRuntimeMinimum_amd64\cab1.cab.
[03A0:05E0][2018-12-05T19:27:41]i304: Verified existing payload: vcRuntimeAdditional_x64 at path: C:\ProgramData\Package Cache\.unverified\vcRuntimeAdditional_x64.
[03A0:05E0][2018-12-05T19:27:41]i305: Verified acquired payload: vcRuntimeAdditional_x64 at path: C:\ProgramData\Package Cache\.unverified\vcRuntimeAdditional_x64, moving to: C:\ProgramData\Package Cache\{DFFEB619-5455-3697-B145-243D936DB95B}v14.0.23918\packages\vcRuntimeAdditional_amd64\vc_runtimeAdditional_x64.msi.
[03A0:05E0][2018-12-05T19:27:41]i304: Verified existing payload: cab2C04DDC374BD96EB5C8EB8208F2C7C92 at path: C:\ProgramData\Package Cache\.unverified\cab2C04DDC374BD96EB5C8EB8208F2C7C92.
[03A0:05E0][2018-12-05T19:27:41]i305: Verified acquired payload: cab2C04DDC374BD96EB5C8EB8208F2C7C92 at path: C:\ProgramData\Package Cache\.unverified\cab2C04DDC374BD96EB5C8EB8208F2C7C92, moving to: C:\ProgramData\Package Cache\{DFFEB619-5455-3697-B145-243D936DB95B}v14.0.23918\packages\vcRuntimeAdditional_amd64\cab1.cab.
[03A0:05E0][2018-12-05T19:27:41]i304: Verified existing payload: Windows81_x64 at path: C:\ProgramData\Package Cache\.unverified\Windows81_x64.
[03A0:05E0][2018-12-05T19:27:41]i305: Verified acquired payload: Windows81_x64 at path: C:\ProgramData\Package Cache\.unverified\Windows81_x64, moving to: C:\ProgramData\Package Cache\3ACBF3890FC9C8A6F3D2155ECF106028E5F55164\packages\Patch\x64\Windows8.1-KB2999226-x64.msu.
[03A0:0728][2018-12-05T19:27:41]i301: Applying execute package: vcRuntimeMinimum_x64, action: Install, path: C:\ProgramData\Package Cache\{7B50D081-E670-3B43-A460-0E2CDB5CE984}v14.0.23918\packages\vcRuntimeMinimum_amd64\vc_runtimeMinimum_x64.msi, arguments: ' MSIFASTINSTALL="7" NOVSUI="1"'
[0824:1228][2018-12-05T19:27:43]i319: Applied execute package: vcRuntimeMinimum_x64, result: 0x0, restart: None
[03A0:0728][2018-12-05T19:27:43]i325: Registering dependency: {dab68466-3a7d-41a8-a5cf-415e3ff8ef71} on package provider: Microsoft.VS.VC_RuntimeMinimumVSU_amd64,v14, package: vcRuntimeMinimum_x64
[03A0:0728][2018-12-05T19:27:43]i301: Applying execute package: vcRuntimeAdditional_x64, action: Install, path: C:\ProgramData\Package Cache\{DFFEB619-5455-3697-B145-243D936DB95B}v14.0.23918\packages\vcRuntimeAdditional_amd64\vc_runtimeAdditional_x64.msi, arguments: ' MSIFASTINSTALL="7" NOVSUI="1"'
[0824:1228][2018-12-05T19:27:45]i319: Applied execute package: vcRuntimeAdditional_x64, result: 0x0, restart: None
[03A0:0728][2018-12-05T19:27:45]i325: Registering dependency: {dab68466-3a7d-41a8-a5cf-415e3ff8ef71} on package provider: Microsoft.VS.VC_RuntimeAdditionalVSU_amd64,v14, package: vcRuntimeAdditional_x64
[03A0:0728][2018-12-05T19:27:45]i301: Applying execute package: Windows81_x64, action: Install, path: C:\ProgramData\Package Cache\3ACBF3890FC9C8A6F3D2155ECF106028E5F55164\packages\Patch\x64\Windows8.1-KB2999226-x64.msu, arguments: '"C:\Windows\SysNative\wusa.exe""C:\ProgramData\Package Cache\3ACBF3890FC9C8A6F3D2155ECF106028E5F55164\packages\Patch\x64\Windows8.1-KB2999226-x64.msu" /quiet /norestart'
[03A0:0728][2018-12-05T19:28:02]e000: Error 0x80240017: Failed to execute MSU package.
[0824:1228][2018-12-05T19:28:02]e000: Error 0x80240017: Failed to configure per-machine MSU package.
[0824:1228][2018-12-05T19:28:02]i319: Applied execute package: Windows81_x64, result: 0x80240017, restart: None
[0824:1228][2018-12-05T19:28:02]e000: Error 0x80240017: Failed to execute MSU package.
[03A0:0728][2018-12-05T19:28:02]i372: Session end, registration key: SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{dab68466-3a7d-41a8-a5cf-415e3ff8ef71}, resume: ARP, restart: None, disable resume: No
[03A0:0728][2018-12-05T19:28:02]i371: Updating session, registration key: SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{dab68466-3a7d-41a8-a5cf-415e3ff8ef71}, resume: ARP, restart initiated: No, disable resume: No
[0824:1228][2018-12-05T19:28:02]i399: Apply complete, result: 0x80240017, restart: None, ba requested restart:  No

What is the default stack size?

$
0
0
I encountered a crash of a program which uses deep recursion. I developed it with Visual C++ in VS2015. After I set Project Properties -> Linker -> System -> Stack Reserve Size & Stack Commit Size from empty to a large value, say, 1000000000 (1GB), the program runs correctly. So obviously the problem was caused by the small default stack size set by VS2015. So I'm curious what on earth the default stack size is? I am using Visual Studio 2015 Update 3 on Windows 10 64 bit, so I'm only interested in the value on that platform. A link to a document webpage together with the default value would be appreciated. Thank you.

How can get TragetTexture ImageData?

$
0
0

I use DirectX11 and want to get ImageData by Map function.
I created the Texture like below.

////////////////////////////////////////////////////////////////////////////////
 D3D11_TEXTURE2D_DESC Desc;
 ZeroMemory(&Desc, sizeof(D3D11_TEXTURE2D_DESC));
 Desc.ArraySize = 1;
 Desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
 Desc.Usage = D3D11_USAGE_DEFAULT; 
 Desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; 
 Desc.Width = m_nSize.x;
 Desc.Height = m_nSize.y;
 Desc.MipLevels = 1;
 Desc.SampleDesc.Count = 1;
 Desc.SampleDesc.Quality = 0;
////////////////////////////////////////////////////////////////////////////////

But Map fuction of the context return fail.
Is there any way to get ImageData of Target Texture?

Only Grabbing Icon shows black color while saving in Visual C++

$
0
0

Hi All,

 I want to save a icon to a file in VC++. Please find the below code that I'm using. I could save all the icons being saved successfully. But when I try to save the grabbing icon to the local hard disk there is a black background around the image.

Please find the below code snippet.

        CURSORINFO ci;
ci.cbSize = sizeof(ci);
GetCursorInfo(&ci);
HICON hico = ci.hCursor;
ICONINFO iconInfo;
GetIconInfo(ci.hCursor, &iconInfo);

BYTE  buf[4096];
LONG cbSize = 0;

PICTDESC pd = {sizeof(pd), PICTYPE_ICON};
pd.icon.hicon = ci.hCursor;
CComPtr<IPicture> pPict = NULL;
CComPtr<IStream>  pStrm = NULL;
BOOL res = FALSE;
res = SUCCEEDED( ::CreateStreamOnHGlobal(NULL, TRUE, &pStrm) );
res = SUCCEEDED( ::OleCreatePictureIndirect(&pd, IID_IPicture, FALSE, (void**)&pPict) );
res = SUCCEEDED( pPict->SaveAsFile( pStrm, TRUE, &cbSize ) );

if( res )
{
          // rewind stream to the beginning
           LARGE_INTEGER li = {0};
           pStrm->Seek(li, STREAM_SEEK_SET, NULL);
         // write to file
         HANDLE hFile = ::CreateFile("E:\\abc.jpeg", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
           if( INVALID_HANDLE_VALUE != hFile )
              {
               DWORD dwWritten = 0, dwRead = 0, dwDone = 0;
                      while( dwDone < cbSize )
                              {
                               if( SUCCEEDED(pStrm->Read(buf, sizeof(buf), &dwRead)) )
                                    {
                                       ::WriteFile(hFile, buf, dwRead, &dwWritten, NULL);
                                         if( dwWritten != dwRead )
                                                 break;
                                               dwDone += dwRead;
                                      }
                                     else
                                        break;
                 }
                        _ASSERTE(dwDone == cbSize);
                      ::CloseHandle(hFile);
        }

}

Please find the below grabbing icon.

Grabbing Icon

Thank you in advance for the help.




VC++ 2005 and 2008 are installed with windows 2012 and SQL instance 2012.

$
0
0

Hi,

We have tested a Scenario where we just installed a new windows server 2012 and there was VC++ 2005 and 2008 installed.

I removed both components and installed SQL 2012 and found the VC++ 2005 and 2008 installed again.

Then removed both components and the next day I found the components re-installed automatically after removal.

Is there a recovery point for those components or does SQL 2012 require VC++ 2005 or 2008 ? 

The reason for removal is that MS does not support the VC++ 2005 and 2008 anymore as they are out of support components and doesn't send any new security fixes for them.

WinSrv2012R2 ucrtbase.dll Exception c0000409

$
0
0

Have search internet long and hard for answer to this but to no avail:

Have an internally developed exe (64-bit C++ program) which we're trying to run on a Windows Server 2012 R2 box, but fails immediately with the following exception (key parts):

Problem Event Name: BEX64

Fault Module Path: c:\windows\system32\ucrtbase.dll

Fault Module Version: 10.0.10586

Exception Code: c0000409

We believe there is no issue with our app because it runs fine on another WinSrv2012R2 box of a similar build, and have checked and can confirm that the dll is present in the system32 folder (and syswow64 folder). Any help would be greatly appreciated.

Thank you.


Problem with the first program

$
0
0

When I try to start a new program for example:

#include "stdafx.h"

#include <iostream> int main() { std::cout<< "Hello world and all that" << std::endl; return 0; }

I have a problem:

1>------ Build started: Project: ConsoleApplication1, Configuration: Debug Win32 ------
1>  Source.cpp
1>c:\users\lm\source.cpp(2): warning C4627: '#include <iostream>': skipped when looking for precompiled header use
1>          Add directive to 'stdafx.h' or rebuild precompiled header
1>c:\users\lm\source.cpp(9): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
1>  ConsoleApplication1.cpp
1>c:\users\lm\consoleapplication1.cpp(4): warning C4627: '#include <iostrem>': skipped when looking for precompiled header use
1>          Add directive to 'stdafx.h' or rebuild precompiled header
1>c:\users\lm\consoleapplication1.cpp(13): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
1>  Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========




Unable to create icon using bits and maskbits CreateDIBSection() returns NULL for bmpcolor

$
0
0

Hi All,

 I want to create a icon using SetDIBits() but it returns me a black rectangle. It seems to me like the below line code is returning me a NULL HBITMAP handle.

bmpcolor = CreateDIBSection(dc.GetSafeHdc(), &bmInfo, DIB_RGB_COLORS,(void**)&bits,0, 0);

Please find the entire code below.

#include<iostream>
#include<stdio.h>
#include <afx.h>
#include <afxwin.h>
#include <atlbase.h>
#include <vector> // for vector
#include <iterator> // for std::istream_iterator and std::ostream_iterator
#include <algorithm> // for std::copy
#include <string>
#include <fstream>
#include <sstream>

#include<Windows.h>
#include<list>


int _tmain(int argc, _TCHAR* argv[])
{
	int nColorBits = 32;
	CURSORINFO ci;
	ci.cbSize = sizeof(ci);
	GetCursorInfo(&ci);
	HCURSOR hcursor = ci.hCursor;
	struct ICONDIRENTRY
	{
		UCHAR nWidth;
		UCHAR nHeight;
		UCHAR nNumColorsInPalette; // 0 if no palette
		UCHAR nReserved; // should be 0
		WORD nNumColorPlanes; // 0 or 1
		WORD nBitsPerPixel;
		ULONG nDataLength; // length in bytes
		ULONG nOffset; // offset of BMP or PNG data from beginning of file
	};

	ASSERT(nColorBits == 4 || nColorBits == 8 || nColorBits == 24 || nColorBits == 32);

	if (offsetof(ICONDIRENTRY, nOffset) != 12)
	{
		return false;
	}

	CDC dc;
	dc.Attach(::GetDC(NULL)); // ensure that DC is released when function ends

	// Write header:
	UCHAR icoHeader[6] = {0, 0, 1, 0, 1, 0}; // ICO file with 1 image

	// Get information about icon:
	ICONINFO iconInfo;
	GetIconInfo(ci.hCursor, &iconInfo);
	BITMAPINFO bmInfo = {0};
	bmInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	bmInfo.bmiHeader.biBitCount = 0;    // don't get the color table     
	if (!GetDIBits(dc, iconInfo.hbmColor, 0, 0, NULL, &bmInfo, DIB_RGB_COLORS))
	{
		return false;
	}

	// Allocate size of bitmap info header plus space for color table:
	int nBmInfoSize = sizeof(BITMAPINFOHEADER);
	if (nColorBits < 24)
	{
		nBmInfoSize += sizeof(RGBQUAD) * (int)(1 << nColorBits);
	}

	CAutoVectorPtr<UCHAR> bitmapInfo;
	bitmapInfo.Allocate(nBmInfoSize);
	BITMAPINFO* pBmInfo = (BITMAPINFO*)(UCHAR*)bitmapInfo;
	memcpy(pBmInfo, &bmInfo, sizeof(BITMAPINFOHEADER));

	// Get bitmap data:
	ASSERT(bmInfo.bmiHeader.biSizeImage != 0);
	CAutoVectorPtr<UCHAR> bits;
	bits.Allocate(bmInfo.bmiHeader.biSizeImage);
	pBmInfo->bmiHeader.biBitCount = nColorBits;
	pBmInfo->bmiHeader.biCompression = BI_RGB;
	if (!GetDIBits(dc, iconInfo.hbmColor, 0, bmInfo.bmiHeader.biHeight, (UCHAR*)bits, pBmInfo, DIB_RGB_COLORS))
	{
		return false;
	}


	// Get mask data:
	BITMAPINFO maskInfo = {0};
	maskInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	maskInfo.bmiHeader.biBitCount = 0;  // don't get the color table     
	if (!GetDIBits(dc, iconInfo.hbmMask, 0, 0, NULL, &maskInfo, DIB_RGB_COLORS))
	{
		return false;
	}
	ASSERT(maskInfo.bmiHeader.biBitCount == 1);
	CAutoVectorPtr<UCHAR> maskBits;
	maskBits.Allocate(maskInfo.bmiHeader.biSizeImage);
	CAutoVectorPtr<UCHAR> maskInfoBytes;
	maskInfoBytes.Allocate(sizeof(BITMAPINFO) + 2 * sizeof(RGBQUAD));
	BITMAPINFO* pMaskInfo = (BITMAPINFO*)(UCHAR*)maskInfoBytes;
	memcpy(pMaskInfo, &maskInfo, sizeof(maskInfo));
	if (!GetDIBits(dc, iconInfo.hbmMask, 0, maskInfo.bmiHeader.biHeight, (UCHAR*)maskBits, pMaskInfo, DIB_RGB_COLORS))
	{
		return false;
	}

	// Write directory entry:
	ICONDIRENTRY dir;
	dir.nWidth = (UCHAR) pBmInfo->bmiHeader.biWidth;
	dir.nHeight = (UCHAR) pBmInfo->bmiHeader.biHeight;
	dir.nNumColorsInPalette = (nColorBits == 4 ? 16 : 0);
	dir.nReserved = 0;
	dir.nNumColorPlanes = 0;
	dir.nBitsPerPixel = pBmInfo->bmiHeader.biBitCount;
	dir.nDataLength = pBmInfo->bmiHeader.biSizeImage + pMaskInfo->bmiHeader.biSizeImage + nBmInfoSize;
	dir.nOffset = sizeof(dir) + sizeof(icoHeader);

	// Write DIB header (including color table):
	int nBitsSize = pBmInfo->bmiHeader.biSizeImage;
	pBmInfo->bmiHeader.biHeight *= 2; // because the header is for both image and mask
	pBmInfo->bmiHeader.biCompression = 0;
	pBmInfo->bmiHeader.biSizeImage += pMaskInfo->bmiHeader.biSizeImage; // because the header is for both image and mask

	HBITMAP bmpmask = NULL;
	HBITMAP bmpcolor = NULL;
	unsigned char* lpBitmapBits = NULL;

	bmpcolor = CreateDIBSection(dc.GetSafeHdc(), &bmInfo, DIB_RGB_COLORS,(void**)&bits,0, 0);
	bmpmask = CreateDIBSection(NULL, &maskInfo, DIB_RGB_COLORS,(void **)&maskBits, NULL, 0);
	int  mask = SetDIBits(NULL, bmpmask, 0, maskInfo.bmiHeader.biHeight, (UCHAR*)maskBits, pMaskInfo, DIB_RGB_COLORS);
	int colo = SetDIBits(NULL, bmpcolor, 0, bmInfo.bmiHeader.biHeight, (UCHAR*)bits, pBmInfo, DIB_PAL_COLORS);

	ICONINFO in;
	HICON ii = NULL;
	in.hbmColor = bmpcolor;// iconinfo.hbmColor;
	in.hbmMask = bmpmask;// iconinfo.hbmMask;
	in.fIcon = TRUE;
	ii = CreateIconIndirect(&in);
	if(ii == NULL)
		MessageBox(NULL,L"Couldn't create Cursor NULL",L"NULL",0);
	::SetSystemCursor((HCURSOR)ii,32512);
	getchar();
}

Could you please let me know why the bmpcolor is returning NULL ? or is there anything I'm passing is wrong.

Thanks,

Vinay


C# DataSet 90 seconds faster than MFC CRecordset ?!?!?!?!?!?!?!?

$
0
0
ok I'm just trying to execute a query into a recordset, nothing out of the ordinary here.
C# Code:
while (reader.Read())
         {int i1 = reader.GetInt32(0),
             i2 = reader.GetInt16(1),
             i3 = 0;if (!reader.IsDBNull(2))
           {
             i3 = reader.GetInt32(2);
             bolNullFound = false;//str3 = Convert.ToString(i3);
           }else
             bolNullFound = true;

           ++counter1; // Console.WriteLine(reader.GetInt16(1)); //Start of TEST
           DataRow row = ds2.Tables["T1Test"].NewRow();
           row["EventID"] = i1;
           row["EventCode"] = i2;if (bolNullFound == false)
           {
             row["DebtID"] = i3;
           }else
             row["DebtID"].Equals(DBNull.Value);

           ds2.Tables["T1Test"].Rows.Add(row);
         }

in C++ we have:

CDatabase cd;
     CRecordset sourcers(&cd);
	   CString DSNString = _T("DSN=database;UID=sa;PWD=password;"), 
			   SQLString = _T("SELECT EventID, EventCode, Debtid FROM Events WHERE Eventcode IN (10, 16)");try
	   {
      cd.OpenEx(DSNString, NULL );
	   }catch(CDBException *e )
	   {
	    AfxMessageBox(_T("Didn't open ODBC database.\n") + e->m_strError);throw;
	   }try
     {
      sourcers.Open( CRecordset::snapshot , SQLString );
     }catch(CDBException *e )
     {
      AfxMessageBox(_T("failed opening ODBC CRecordset ") + e->m_strError);throw; 
     }int fieldcount = sourcers.GetODBCFieldCount( ), i, rec; 
     CDBVariant varValue;//CString tstring;longint tc = 0;
     printf("Starting...\n");
     CTime starttime = CTime::GetCurrentTime();if ( !sourcers.IsEOF() )
      sourcers.MoveFirst();while ( !sourcers.IsEOF())
     {for ( i = 0; i < fieldcount; ++ i ) // do nothing other than load field into tstring
        sourcers.GetFieldValue(i, varValue);
       ++tc;//			} // end for rectry
      {
       sourcers.MoveNext();
      }catch( CDBException *e )
      {
	     AfxMessageBox( _T("MoveNext Failed: ") + e->m_strError);throw; 
      }
     } // end while
The C# takes around 1 second to complete for 85,000 records and the C++ is taking around 90 seconds for the same 85,000 records this is all being done over the network.  Run locally it's about 10 seconds for the C++ app.
Any ideas as to why this is so much slower?  This is with Windows 2008 Server, and SQL Server 2000.  Running this on our other network with Windows 2000 Server and SQL Server 2000 it runs in 12 - 15 seconds (C++ tested only not C#)

How to force dpi scale factor to 100% on win10 computer from GPO or from ur C++/C# software

$
0
0

Hi

We would like to force the scale factor to 100% on the screen linked to the win 10 computer where our product is installed...But we Don't find how to do that in C++/C#

with winuser.h we succeed to retrieve the information of the scale factor but not to change it to 100% especially

we are the only software launched on the computer...the computer is dedicated to our software. When we link the screen to the box and the resolution is too high Windows put automatically the scale to 150% but we want to force the 100% everytime we Don'twant to let Windows to adapt the DPI (because we broadcast Something on the screen and we Don't need to have more than 100% otherwise it is not broadcasted correctly), so we need to stop the auto scaling or to force the 100% when our soft is launched.


and we need to modify dpi directly because we need that the dpi is 100% for our process but also for IE process that we can use.

does anyone already do that?

thanks

utility file troubles

$
0
0
I'm trying to compile a project converted from vb6 to vs2010 and the convertion had warnings most were VCWebServiceProxyGeneratorTool is no longer supported and some were Attribute 'Detect64BitPortabilityProblems' of 'VCCLCompilerTool' is not supported in this version and has been removed during conversion and the rest were program was updated to include the UAC. i'm trying to build the program and seem to get the same two errors both in the utility filec:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(163): error C2440: 'initializing' : cannot convert from 'int' to 'const unsigned char *' and c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(163): error C2439: 'std::_Pair_base<_Ty1,_Ty2>::first' : member could not be initialized both include this code

_Pair_base(_Other1&& _Val1, _Other2&& _Val2)

: first(_STD forward<_Other1>(_Val1)),

second(_STD forward<_Other2>(_Val2))

error occurs here > {

 

// construct from moved values 

}

_Ty1 first;

 

// the first stored value

_Ty2 second;

 

// the second stored value

};

template

 

 

<class _Ty1,

 

 

class _Ty2>

any help would be great. 

VS 2107, "traditional" (C++ only) Windows app project, would not change Character Set.

$
0
0

Hi!

Something happened to my "traditional"Windows app project (I don't want to use ATL nor MFC with this project). It just switched to Multibyte char set, and changing the setting in Project properties (GUI) would not help.

I also tried #define UNICODE in header file, no luck, all WinApis default to A which creates huge problem.

I thought that maybe some global setting kicked in in my Visual Studio installation, so I opened another Windows app project, and this time it defaulted to UNICODE, and would not switch to Multibyte. Strange. 

Would you have any idea what might happen, and where I could start looking to have this fixed?

Thank you!

SendMessage

$
0
0

Hi,

Is it possible I can send input and get output through sendmessage() api.

If I pass index to sendmessage, I have to get int or cstring or pointer as return data?


Windows message pumps and how Operating system sends messages

$
0
0

Hi,

I have an application that has many plugins and all added as forms into one window (as sheets of a tabbed pane). The thing is there are many components on each of plug ins and some of these components cause time consuming jobs due to processing of windows messages. There is one message pump (message loop, excuse me if I do not use the terminology correctly). Time consuming jobs on one of the plugins cause complete application to lag.

I am aware that I can try to get rid of time consuming jobs in processing messages. That is at hand, but what I want is different message pumps to run for each plug in and in this way a lag occurring in windows message pump of a plugin will not cause lag in main window.

When I read following in Microsoft documentation:

https://docs.microsoft.com/en-us/windows/desktop/LearnWin32/window-messages 

"For each thread that creates a window, the operating system creates a queue for window messages. This queue holds messages for all the windows that are created on that thread. The queue itself is hidden from your program. You cannot manipulate the queue directly. However, you can pull a message from the queue by calling theGetMessage function."

I thought that if I create each window in separate thread, it will be enough.  I tried, create 2 windows in separate threads and saw that their message pumps are not effecting one another. But these 2 windows are completely separated.

When I created one of them as child of the other, although the message pumps are separate, if there is a time consuming job in message loop of child, the parent is also lagged. Somehow the operating system is pausing the message queue of parent window. Below is the way I do it.

Is it possible what I want? Can I create a child window that has a separate message pump and not lagging the parent. And is it the correct way? If not what is the correct way to separate message pumps between parent and child windows? 

Note: I try to use win32 api

#ifndef UNICODE
#define UNICODE
#endif 

#define _CRT_SECURE_NO_WARNINGS

#include <windows.h>
#include "resource.h"
#include <stdio.h>

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK DialogProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

HWND _hwnd1;
HWND _hwnd2;

DWORD WINAPI threadSvc(LPVOID lpParam);
DWORD WINAPI threadSvc_1(LPVOID lpParam);
DWORD WINAPI threadSvc_2(LPVOID lpParam);

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
{



	/*Start a thread for trial*/
#if 1
	DWORD   dwThreadId1 = NULL;
	HANDLE myThread1 = CreateThread(NULL,                   	// default security attributes
									0,                      	// use default stack size  
									threadSvc_1,			    // thread function name
									/*pDataArray[i]*/&hInstance,// argument to thread function 
									0,                      	// use default creation flags &dwThreadId1);   			// returns the thread identifier 

	if (myThread1 == NULL)
		OutputDebugStringA("thread 1 failed to start\n");
	else 
		OutputDebugStringA("thread 1 started\n");
#endif
	Sleep(2000);
#if 1
	DWORD   dwThreadId2 = NULL;
	HANDLE myThread2 = CreateThread(NULL,                   	// default security attributes
									0,                      	// use default stack size  
									threadSvc_2,			    // thread function name
									/*pDataArray[i]*/&hInstance,// argument to thread function 
									0,                      	// use default creation flags &dwThreadId2);   			// returns the thread identifier 
	if (myThread2 == NULL)
		OutputDebugStringA("thread 2 failed to start\n");
	else
		OutputDebugStringA("thread 2 started\n");
#endif

	// wait
	while (1) Sleep(1000);



	// Run the message loop. - no need for a message loop  as it is does not have a window.
//	MSG msg = { };
//	while (GetMessage(&msg, NULL, 0, 0))
//	{
//		TranslateMessage(&msg);
//		DispatchMessage(&msg);
//	}

	return 0;
} //wWinMain returns

LRESULT CALLBACK WindowProc1(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	DWORD threadId = GetCurrentThreadId();
	char buf[512] = {};
	sprintf(&buf[0], "barman: WindowProc1 [threadId=%08ul] [msgId=%04u]\n", threadId, uMsg);
	OutputDebugStringA(buf);

	switch (uMsg)
	{
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;

	case WM_SETCURSOR:
		OutputDebugStringA("WM_SETCURSOR \n");
		return 0;
#if 1
	case WM_PAINT:
	{
		PAINTSTRUCT ps;
		HDC hdc = BeginPaint(hwnd, &ps);
		FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_WINDOW + 1));
		EndPaint(hwnd, &ps);
	}
	return 0;
#endif
	}
	// to default window processor
	return DefWindowProc(hwnd, uMsg, wParam, lParam);
}

LRESULT CALLBACK WindowProc2(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	DWORD threadId = GetCurrentThreadId();
	char buf[512] = {};
	sprintf(&buf[0], "barman: WindowProc2 [threadId=%08ul] [msgId=%04u]\n", threadId, uMsg);
	OutputDebugStringA(buf);
	switch (uMsg)
	{
		case WM_DESTROY:
			PostQuitMessage(0);
			return 0;

		case WM_PAINT:
		{
			PAINTSTRUCT ps;
			HDC hdc = BeginPaint(hwnd, &ps);
			FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_WINDOW + 5));
			EndPaint(hwnd, &ps);
		}
		return 0;
#if 0
		case WM_NCHITTEST:
		{
			PostMessage(_hwnd1, WM_NCHITTEST, wParam, lParam);
		}
		return DefWindowProc(hwnd, uMsg, wParam, lParam);
#endif
		case WM_LBUTTONDOWN:
		{
			sprintf(&buf[0], "barman: MOUSE CLICKED... [threadId=%ul]\n", threadId);
			OutputDebugStringA(buf);
#if 1
			/*To create a lag in msg queue 100 millions*/
			for (long i = 0; i < 100000000; i++)
			{
				printf("de");
			}
#endif
		}
		return 0;

	} // switch case ends
	// to default window processor
	return DefWindowProc(hwnd, uMsg, wParam, lParam);
}

/*useless thread*/
DWORD WINAPI threadSvc(LPVOID lpParam)
{
	while (1)
	{
		OutputDebugStringA("thread running\n");
		Sleep(500);
	}
	return 0;
}

// start a window and register it then process its message queue
DWORD WINAPI threadSvc_1(LPVOID lpParam)
{

	WNDCLASS wc1 = { };
	const wchar_t CLASS_NAME_1[] = L"First sample window class ";
	wc1.lpfnWndProc = WindowProc1; // win proc for the message pump
	wc1.hInstance = *((HINSTANCE*)lpParam);
	wc1.lpszClassName = CLASS_NAME_1;

	RegisterClass(&wc1);

	_hwnd1 = CreateWindowEx(0,								// ex style id DWORD
							CLASS_NAME_1,					// class name
							L"Learn to Program Windows 1 ", // window name
							WS_OVERLAPPEDWINDOW				// style
							| WS_CLIPCHILDREN,				// for parent not to overpaint the child window. 
							CW_USEDEFAULT,					// Size and position
							CW_USEDEFAULT,					// Size and position
							CW_USEDEFAULT,					// Size and position
							CW_USEDEFAULT,					// Size and position
							NULL,							// parent window
							NULL,							// ?? hMenu
							*((HINSTANCE*)lpParam),			// hInstance
							NULL);							// lpParam - type LPVOID->long pointer of type void

	if (_hwnd1 == NULL)
	{
		return 0;
	}

	ShowWindow(_hwnd1, 5); 
	MSG msg = { };
#if 1

	char buf[512] = {};
	
	BOOL getMessageResult = false; 
	
	while (getMessageResult = GetMessage(&msg, NULL, 0, 0) != 0)
	{
		if (getMessageResult == -1)
		{
			sprintf(&buf[0], "task 1 message loop get message returned error [threadID:%04ul]\n", GetCurrentThreadId());
			OutputDebugStringA(buf);
			return 0;
		}
		else
		{
			sprintf(&buf[0], "Thread-1 before Dispatch Message [threadId:%04ul] [WHND:%d]\n", GetCurrentThreadId(), msg.hwnd);
			OutputDebugStringA(buf);
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}

		
		sprintf(&buf[0], "Thread-1 after Dispatch Message [threadId:%04ul] [WHND:%d]\n", GetCurrentThreadId(), msg.hwnd);
		OutputDebugStringA(buf);
	}
#endif


#if 0
	//PeekMessage loop example
	while (WM_QUIT != msg.message)
	{
		while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) > 0) //Or use an if statement
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}
#endif
	return 0;
}

DWORD WINAPI threadSvc_2(LPVOID lpParam)
{
	WNDCLASS wc2 = { };
	const wchar_t CLASS_NAME_2[] = L"Second sample window class";
	wc2.lpfnWndProc = WindowProc2;
	wc2.hInstance = *((HINSTANCE*)lpParam);
	wc2.lpszClassName = CLASS_NAME_2;

	RegisterClass(&wc2);

	_hwnd2 = CreateWindowEx(0,
							CLASS_NAME_2,
							L"Learn to Program Windows 2 ",
							WS_CHILD					// Styles that are used. 
							| WS_VISIBLE  
							//| WS_CAPTION
							//| WS_SYSMENU
							//| WS_THICKFRAME
							//| WS_MINIMIZEBOX
							//| WS_MAXIMIZEBOX
							/* WS_OVERLAPPEDWINDOW*/,
							// Size and position
							CW_USEDEFAULT, CW_USEDEFAULT, 300, 300,
							_hwnd1 /*NULL*/, // parent window
							NULL,
							*((HINSTANCE*)lpParam),
							NULL);

	if (_hwnd2 == NULL)
	{
		return 0;
	}

	ShowWindow(_hwnd2, 5);
	MSG msg = { };
	
#if 1
	while (GetMessage(&msg, NULL, 0, 0))
	{
		if (msg.hwnd == _hwnd2)
		{
			TranslateMessage(&msg);
			OutputDebugString(L"Thread-2 before Dispatch Message\n");
			DispatchMessage(&msg);
			OutputDebugString(L"Thread-2 after Dispatch Message\n");
		}
		else
		{
			OutputDebugString(L"Thread-2 ignored a msg\n");
		}

		
	}
#endif


#if 0
	//PeekMessage loop example
	while (WM_QUIT != msg.message)
	{
		while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) > 0) //Or use an if statement
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}
#endif

	return 0;
}


C++ CreateProcess Telnet

$
0
0

Hello, I have problem with CreateProcess and Telnet. The main question is why telnet.exe file contains:

'telnet' is not recognized as an internal or external command,

operable program or batch file.

I checked on PC telnet is installed. Where is problem?

void SaveResult(const wchar_t *fileName, const wchar_t *commandLine)
{
    SECURITY_ATTRIBUTES sa;
    sa.nLength = sizeof(sa);
    sa.lpSecurityDescriptor = NULL;
    sa.bInheritHandle = TRUE;

    HANDLE h = CreateFile(fileName, FILE_WRITE_DATA, FILE_SHARE_WRITE | FILE_SHARE_READ,
        &sa, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    if(h == INVALID_HANDLE_VALUE)
        return;

    PROCESS_INFORMATION pi = { 0 };
    STARTUPINFO si = { sizeof(si) };
    si.dwFlags |= STARTF_USESTDHANDLES;
    si.hStdInput = NULL;
    si.hStdError = h;
    si.hStdOutput = h;

    wchar_t *writable_cmdline = _wcsdup(commandLine);
    BOOL success = CreateProcess(NULL, writable_cmdline,
        NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi);

    bool finished = false;

    //wait for 1 second
    for(int i = 0; i < 10; i++)
    {
        if(WaitForSingleObject(pi.hProcess, 100) <= 0)
        {
            finished = true;
            break;
        }
    }

    if(success)
    {
        CloseHandle(pi.hProcess);
        CloseHandle(pi.hThread);
    }

    CloseHandle(h);
    free(writable_cmdline);

    if(!finished)
        printf("Process didn't finish\n");
}


int main()
{
    SaveResult(L"telnet.txt", L"C:\\windows\\system32\\cmd.exe /c telnet");
    SaveResult(L"ipconfig.txt", L"C:\\windows\\system32\\cmd.exe /c ipconfig");
    return 0;
}

Disapearing Ink?

$
0
0

Hi Folks:

   Developing on Windows 10 Pro, VS 2017 Community, all C++, Win32, no MFC.

   My application produces a report.  The same function draws the report on a display or to a printer. 

   A user might produce multiple reports during the time the program is running. 

   Lines are drawn to separate sections of the report and practically every number is surrounded by a black rectangle. 

   This starts out fine, and can work great for a lot of reports.  Then, for some reason, the lines and rectangles stop being displayed. 

   I have code to simulate a user in order to test the application.  Thousands of reports can be generated while running a test.  These start out fine, but after 5, 10  or 100 reports, all of the lines and rectangles disappear while the text in the reports is just fine. 

   I've proceeded a call to Rectangle() with the following in an effort to figure out what's causing this:

#ifdef _DEBUG

            COLORREF current_pen_color = SetDCPenColor(hdc, 0x00);

            if (current_pen_color != 0)
            {
                int test_x = 0;
            }

            SetDCPenColor(hdc, current_pen_color);
#endif

            Rectangle(hdc, rectangle_frame.left, 
                                    rectangle_frame.top,
                                        rectangle_frame.right,
                                            rectangle_frame.bottom);

   My plan is to see when the pen color stopped being black, but a break point at thetest_x = 0 line is never triggered. 

   Suggestions on what I'm doing wrong, or how I might track down the issue are appreciated.

      Thanks
      Larry


Painting to a tabPage

$
0
0

Hello,

I am attempting to write a program that will need to paint fillRectangles to a tabPage anytime the user selects a specific tabPage. I am having trouble figuring out how to do this, as it seems like I would need to somehow manually call the tabPage_Paint event, but I'm not even sure if that's what I'd have to do.

In essence, the code should look like this:

private: System::Void TabControl1_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e)
	{
		if(TabControl1->SelectedTab==tabPage1)
		{
			//Draw a fillRectangle on tabPage1
		}
	}


Clipboard: unable to enum registered clipboard formats as Local System

$
0
0

I have a simple app that monitors and lists all clipboard formats available on the system clipboard whenever the clipboard is updated. It works totally fine in almost all scenarios. The only problem is that when the app is ran as Local System AND the clipboard is updated with registered formats (i.e. copying RTF text in MS Word), the list of formats I get from iterating over EnumCLipboardFormats is incomplete. The iterated calls to EnumClipboardFormats ends after grabbing the very first format (which is always "DataObject" - 49161) because the subsequent call always returns 0 with ERROR_SUCCESS (meaning there is no more format to return). According to the test case where the app is running as the logged-on user, copying the exact same data (RTF text in this case) should have resulted in listing >5 formats. Also, when I am dealing with standard clipboard formats (i.e. copying plain-text from notepad), I don't have this issue at all. Regardless of which user the app is running as, the list I get returned from the iterated calls to EnumClipboardFormats is always the same. It's super weird. To me, it seems like the other formats that are not getting returned from the enum call is "hidden" in some sense, but I was unable to find any documentation providing clues to explain this behavior, and I have not found any article or thread talking about this issue. 

I've already tried impersonating the logged-on user, but that did not help. Impersonation was successful, but the iteration over EnumClipboardFormats still ended after giving me the first format.

For clarity, these are the test cases:

1. Run the app as the logged-on user + update the clipboard with a standard format (plain-text from notepad) = Iterated enum returns the full list of formats

2. Run the app as the logged-on user + update the clipboard with a registered format (RTF text from MS Word) = Iterated enum returns the full list of formats

3. Run the app as Local System + update the clipboard with a standard format (plain-text from notepad) = Iterated enum returns the full list of formats

4. Run the app as Local System + update the clipboard with a registered format (RTF text from MS Word) = Iterated enum returns an imcomplete list (always iterated over for only a single format)

Does anyone know what is causing this inconsistency and what the solution is to fix it?

Viewing all 15302 articles
Browse latest View live


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