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

error function

$
0
0

what is it error function ? How can i call it . in what kind of library placed it ? i meet with this function and i do not know nothing about her .

e.g : error("I think") .


Is HINSTANCE Still A Real Thing?

$
0
0

Hello Folks:

   Developing on Windows 10, C++. 

   Do Windows libraries still use HINSTANCE, or is that parameter just a relic for compatibility from the times when Windows was a wrapping for DOS. 

   When a function I'm using requires it, I'll often just grab it with a call to GetWindowLongPtr().  Right now I need HINSTANCE in a function wasn't passed a handle to a window. 

   An obvious solution is to pass an HINSTANCE globally, but I've always been adverse to using global variables. 

   If Windows still uses HINSTANCE, is there some way of acquiring it inside a function doesn't know about a particular window? 

      Thanks
      Larry

Qt in VS 2015 comm edn

$
0
0

I had created a sample Qt application (Main window) in Visual Studio 2015 comm. edn. And i get this error:

1>------ Rebuild All started: Project: Test2, Configuration: Debug Win32 ------
1>  Moc'ing test2.h...
1>  The filename, directory name, or volume label syntax is incorrect.
1>  Uic'ing test2.ui...
1>  The filename, directory name, or volume label syntax is incorrect.
1>  Rcc'ing test2.qrc...
1>  The filename, directory name, or volume label syntax is incorrect.
1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(171,5): error MSB6006: "cmd.exe" exited with code 123.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

Could someone please help me here. Thanks in advance.


WindowsDesktopApplication calculator problem

$
0
0
Hello, I must to make calculator with WindowsDesktopApplication but I have problem even with the reading the text from edit control. The numbers must to be entered with buttons 0,1,2... and the symbols too ".", "+"... But I cant find any way to enter numbers, when I try SetDlgItemText(hDlg, IDC_EDIT3,  66); it say "argument of type int is incompatible with parameter of type LPCWSTR", when I try SetDlgItemText(hDlg, IDC_EDIT3,  (LPCWSTR)66); The program crash when this function is started. So I must to find way to enter for example 12.4 with symbols. I'm desperate, I have studied this langue only couple of weeks years ago and now I dont know what to do.Please help me, thanks.

Why to use "explicit" keyword with template in C++

$
0
0

Hello All,

In the template function we are using "explicit" keyword. I wanted to know why to use "explicit" keyword with template.

Below is the code snippet:

RegistryValue.h file

enum RegistryValueKind
{
pkEmpty = 0,
pkBool = 1,
pkArray = 2
};

class RegistryValue
{
private:

RegistryValueKindmKind;

public:
typedef std::vector<RegistryValue*> ArrayVal;

public:

bool SetValue(const RegistryValue& value)
{
mValue = value;
return true;
}

template <typename T>
explicit RegistryValue(const std::vector<T> & collection) : mKind(pkEmpty)
{
int count = 0;
typename std::vector<T>::const_iterator i;
for (i = collection.begin(); i != collection.end(); i++)
{
(*this)[count++] = *i;
}
}

Because, from the other .cpp file when i am trying to insert a vector into the SetValue function I am getting the below error:

no suitable user-defined conversion from "std::vector<std::wstring,std::allocator<std::wstring>>" to "const RegistryValue" exists.

I resolved this error by removing the explicit keyword. Is it the correct way?

Thanks in Advance,

Why the different results for the two assemblies below?

$
0
0

The code below builds without a problem with the following linker options: /ENTRY =main, /SUBSYSTEM = Not set in the project property page.

.386
.MODEL flat, stdcall
.stack 4096

ExitProcess PROTO STDCALL, dwExitCode: DWORD

.CODE
main PROC
    mov eax, -1
    invoke ExitProcess, 0
main ENDP

END

But when I try to build the similar code below, just replacing main byWinMain, and the linker options /ENTRY = WinMain and /SUBSYSTEM = Not set, the linker complains with the error "LNK1221: a subsystem can't be inferred and must be defined".

.386
.MODEL flat, stdcall
.stack 4096

ExitProcess PROTO STDCALL, dwExitCode: DWORD

.CODE
WinMain PROC
    mov eax, -1
    invoke ExitProcess, 0
WinMain ENDP

END

streamreader readline stops at tabs

$
0
0
I'm using StreamReader.ReadLine() to read in lines from a tab delimited text file.  I've used this literally hundreds of times with no problems.  However, when I'm reading one particular text file, I'm not getting a complete line.  The first line in the file has 4 columns separated by tabs (2 tabs between third and fourth columns).  The first call to ReadLine() reads the first column.  The second call reads the next 2 columns.  The third call reads the last column.  When I step through in the debugger, I can see the tab after the text of the first column on the first read, the tab between the text of the second and third columns but no tab after the third column on the second read, and the fourth column preceded by 2 tabs on the third read.  Does anyone know why ReadLine() is not reading to the end of the line?  

DirectX & Media Foundation [UWP|WIN32] IMFMediaBuffer/IMF2DBuffer to ID3D11Texture2D

$
0
0

Hi.

  I Decide to integrate WebCam (IMFSourceReaderCallback) to my engine and I make some workaround with MFCaptureD3D from Windows Sample. But I get a little confuse about two thing.

1. In my engine, all was synchronize, with CRXMaterial::OnTick. By Example, if you take IMFMediaEngine and ask to read a video (mp4/avi). This one get Texture ID3D11Texture2D1 from ID3D11ShaderResourceView1 and send it back to IMFMediaEngine::TransferFrame and your video frame was copy inside your texture.

Now with IMFSourceReaderCallback you must draw the frame inside IMFSourceReaderCallback::OnReadSample. If i will respect OnTick philosophy I got a idea. Buffering IMFMediaBuffer inside IMFSourceReaderCallback::OnReadSample and take it back inside CRXMaterial::OnTick to transfer inside resource texture.

2. The problem come with example who use IDirect3DSurface9 and YUV color system. In sort, how transfer IMF2DBuffer to ID3D11Texture2D?

OnReadSample

//***************************************************************************
//* Class name    : CRXWebCam
//* Output        : HRESULT
//* Function name : OnReadSample
//* Description   : 
//* Input         : HRESULT hrStatus
//*                 DWORD dwStreamIndex
//*                 DWORD dwStreamFlags
//*                 LONGLONG llTimestamp
//*                 IMFSample* pSample
//***************************************************************************
HRESULT CRXWebCam::OnReadSample(HRESULT hrStatus, DWORD dwStreamIndex, DWORD dwStreamFlags, LONGLONG llTimestamp, IMFSample* pSample)
{
    HRESULT hr = S_OK;
    IMFMediaBuffer* pBuffer = NULL;

    if (FAILED(hrStatus))
        hr = hrStatus;

    if (SUCCEEDED(hr))
    {
        if (pSample)
        {
            hr = pSample->GetBufferByIndex(0, &pBuffer);

            //Buffering the frame
            m_pBuffer = pBuffer;
            m_pBuffer->AddRef();

            // Draw the frame.
        }
    }

    if (SUCCEEDED(hr))
        hr = m_pReader->ReadSample((DWORD)MF_SOURCE_READER_FIRST_VIDEO_STREAM, 0, NULL, NULL, NULL, NULL);
    if (pBuffer) pBuffer->Release();
    pBuffer = NULL;
    return hr;
}

OnTick

//***************************************************************************
// Class name     : CRXMedia
// Function name  : Render
// Description    : Render Media Class
//***************************************************************************
void CRXMaterial::OnTick()
{
	/*IDXGIFactory4* spFactory;
	IDXGIAdapter1* spAdapter;
	IDXGIOutput* spOutput;

	ThrowIfFailed(CreateDXGIFactory2(0, __uuidof(IDXGIFactory4), (void**)&spFactory));
	ThrowIfFailed(spFactory->EnumAdapters1(0, &spAdapter));
	ThrowIfFailed(spAdapter->EnumOutputs(0, &spOutput));*/
	if (m_pMediaEngine)
	{
		if (/*SUCCEEDED(spOutput->WaitForVBlank()) && this && */!m_pMediaEngine->m_spMediaEngine->IsPaused())
		{
			ID3D11Texture2D1* Texture;
			m_pTextureView->GetResource((ID3D11Resource**)&Texture);
			DWORD SizeX;
			DWORD SizeY;
			m_pMediaEngine->m_spMediaEngine->GetNativeVideoSize(&SizeX, &SizeY);

			RECT Rect = { 0,0, (LONG)SizeX, (LONG)SizeY };
			MFVideoNormalizedRect NormRect = { 0.0f, 0.0f, 1.0f, 1.0f };
			MFARGB BackColor = { 0, 0, 0, 255 };

			m_pMediaEngine->TransferFrame(Texture, NormRect, Rect, BackColor);
			Texture->Release();
		}
	}

	if (m_pWebCamEngine)   //HERE
	{			
		if (m_pWebCamEngine->m_pBuffer)
		{
			ID3D11Texture2D1* Texture;
			m_pTextureView->GetResource((ID3D11Resource**)&Texture);

			IMF2DBuffer* m_p2DBuffer = NULL;
			//m_pWebCamEngine->m_pBuffer->QueryInterface(IID_PPV_ARGS(&m_p2DBuffer));
			m_pWebCamEngine->m_pBuffer->QueryInterface(IID_IMF2DBuffer, (void**)&m_p2DBuffer);

			BYTE* ppbScanLine0;
			LONG plStride;

			m_p2DBuffer->Lock2D(&ppbScanLine0, &plStride);

			//YUV to RGB???

			/*for (DWORD y = 0; y < m_Height; y++)
			{
				RGBQUAD* pDestPel = (RGBQUAD*)mapped.pData;
				WORD* pSrcPel = (WORD*)ppbScanLine0;

				for (DWORD x = 0; x < 640; x += 2)
				{
					// Byte order is U0 Y0 V0 Y1

					int y0 = (int)LOBYTE(pSrcPel[x]);
					int u0 = (int)HIBYTE(pSrcPel[x]);
					int y1 = (int)LOBYTE(pSrcPel[x + 1]);
					int v0 = (int)HIBYTE(pSrcPel[x + 1]);

					pDestPel[x] = ConvertYCrCbToRGB(y0, v0, u0);
					pDestPel[x + 1] = ConvertYCrCbToRGB(y1, v0, u0);
				}

				ppbScanLine0 += plStride;
				//mapped.pData += mapped.RowPitch;
			}*/

			//m_pDirect3D->GetD3DDeviceContext()->Unmap(Texture, NULL);
			m_p2DBuffer->Unlock2D();
			m_p2DBuffer->Release();

			Texture->Release();

			if (m_pWebCamEngine->m_pBuffer) m_pWebCamEngine->m_pBuffer->Release();
			m_pWebCamEngine->m_pBuffer = NULL;
		}
	}

	/*spFactory->Release();
	spAdapter->Release();
	spOutput->Release();*/
}



Interfacing VB6 with a DLL written in C++

$
0
0

Hello All,

I am trying to interface my VB6 with a DLL written in C++. The DLL was actually written by someone else here at the company who I do not have access to at the moment.

The function that I need to call is declared as follows:

//int a35dbd7v2(int service, int AC0_CryptoKeyTable, unsigned char* seed, unsigned char* key);
VBDLLFUNC(int) MDNSa35dbd7v2(int service, int AC0_CryptoKeyTable, unsigned char* seed, unsigned char* key) {
return (a35dbd7v2(service, AC0_CryptoKeyTable, seed, key));
}

Where #define VBDLLFUNC(TypeName) DLLEXPORT TypeName __stdcall

The question that I have is this, what would the declare look like in VB6?

What is the equivalent to unsigned char*?

Please advise

Thank you

Gary

Sizeof vs Length vs Capacity in C++

$
0
0

Hello,

What is the differences between Sizeof vs Length vs Capacity in C++?

In the below example:

Length() is 12.

Sizeof() is 28 and capacity is 15.

#include <iostream> 
#include<string>
using namespace std;

int main()
{
    string s;
    getline(cin, s);
    int sl = s.length();
    int so = sizeof(s);
    char* p = new char[sl];
    for (int i = 0; i < sl; i++)
    {
        p[i] = s[i];
    }
    for (int i = 0; i < sl; i++)
    {
        cout << p[i] << " ";
    }
    return 0;
}

when reading the path (%programdata%),how to resolve it to (C:\programdata) using C++?

$
0
0

Hello All,

I am reading the below path
C:\ProgramData\EMR\Registration\RegistrationSubset.xml using strFilePath parameter in the below ReadJsonFile function.

Now, my new requirement is, the same function should process array of paths and then loop through the array of path locations to find and read the available file path.

below is the array of paths. These paths are reading from .json file.

%programdata%\EMR\Registration\Registration_Subset.xml C:\ProgramData\EMR\Registration\RegistrationSubset.xml 
%AppData%\EMR\EMR Setup\REGDATA\registration_subset.xml %AppData%\EMR\EMR Setup\REGDATA\RegistrationSubset.xml 

Please help me how to read array of paths to find the available file path in the below function? And also how to resolve the path (i.e, while reading the path %programdata%\EMR how to change it to C:\programdata\EMR)?

Below is the code snippet:

bool EMRFileReader::ReadJsonFile(const std::wstring &strFilePath, std::wstring &strFileContent)
{
DWORD dwFileAttribute = FILE_ATTRIBUTE_NORMAL;
std::wstring strExtension = ::PathFindExtension(strFilePath.c_str());
if (strExtension.find(BLOB) != std::string::npos)
{
dwFileAttribute = FILE_ATTRIBUTE_ENCRYPTED;
}

HANDLE hFile = NULL;
LPBYTE lpData = NULL;
hFile = CreateFile(strFilePath.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, dwFileAttribute, NULL);
if (INVALID_HANDLE_VALUE == hFile)
{
return false;
}

DWORD dwBytesReadWrite = 0, dwFileSize;
dwFileSize = GetFileSize(hFile, NULL);
lpData = new(nothrow) BYTE[dwFileSize];
if (lpData)
{
ReadFile(hFile, (LPVOID)lpData, dwFileSize, &dwBytesReadWrite, NULL);
}
CloseHandle(hFile);
if (dwBytesReadWrite > 0)
{
wstring strBase64;
string strData = string((char*)lpData);
EncodeBase64(dwBytesReadWrite, strData, strBase64);
strFileContent = strBase64;
}
if (lpData != NULL)
{
delete[] lpData;
}
return true;
}

Thank you,

How to enumeration foreground app in the task manager

$
0
0

How can I use windows API to enumerate foreground application in the task manager?

For example,if i open Edge & task manager.When I run my program, it will list Edge & task manager, not include background process .

DocumentProperties thrown RPC_S_SERVER_UNAVAILABLE(0x000006BA)

$
0
0

   "Exception Settings -> Win32 Exception" need to check above.

     Run the sample code on .exe for the first time,  Microsoft Visual Studio will thrown a exception "RPC_S_SERVER_UNAVAILABLE(0x000006BA)",but can continue to next step.

     Does anyone one have the same problem ?

     I dont know how to modify code. I look forward to your help.

    The C++ sample code is as following:

    CString csPrinterName = L"OneNote"; //printer name

    std::unique_ptr<DEVMODE> pDevMode;
    HANDLE hPrinter = NULL;
    LPWSTR lpWstr = csPrinterName.GetBuffer(csPrinterName.GetLength());
    if (::OpenPrinter(lpWstr, &hPrinter, NULL))
    {
        long lnSize = ::DocumentProperties(NULL, hPrinter, lpWstr, NULL, NULL, 0); //thorwn RPC_S_SERVER_UNAVAILABLE(0x000006BA),but can continue to run
        if (lnSize > 0)
        {
            pDevMode.reset((DEVMODE*)new BYTE[lnSize]());
            if (pDevMode)
            {
                pDevMode->dmSize = (unsigned short)lnSize;

                lnSize = ::DocumentProperties(NULL, hPrinter, lpWstr, pDevMode.get(), NULL, DM_OUT_BUFFER);
                if (lnSize != IDOK)
                {
                       pDevMode.reset();
                } 

            }
        }
        ::ClosePrinter(hPrinter);
    }
    csPrinterName.ReleaseBuffer();

question on nvme driver in using windows apis

$
0
0

        Recently, I have worked on Windows nvme drivers. After reading “Working with NVMe drives” at MSDN

         I know how to send pass through vendor specific cmd to device. But what I want to know is how to send admin cmds and nvm cmds (such as read write) by windows api.

         Can you give me some reference examples.

        

         Thanks!

VS2010 MFC Application ported to VS2019 not starting in Windows 7 getting general error 0x000007b

$
0
0

Only recently moved to VS2019 (using toolset v142)on W10 from VS2010 on W7.  Compiles & runs ok in W10 but executable won't start in W7.  Have checked dependencies & all dlls accounted for - are there any gotchas in doing this port that I may have overlooked?

Error reads, "The application was unable to start correctly (0x000007b). Click OK to close the application."

 

学习敲代码

$
0
0
程序初学者有什么建议吗或者好的学习体系吗?

VS Linux Project - How to target different GCC versions (2) ?

$
0
0

Hi, I am trying to configure Visual Studio 2017 to remotely build a C++ project using CMake on a Linux machine.  The build must use the Red Hat SCL compiler collection, not the default gcc compiler on the machine.

I have specified a prebuild command in CMakeSettings.json:

      "remotePrebuildCommand""source scl_source enable devtoolset-7"

I'm not sure that that will force the scl to be used.  I guess the correct headers won't be downloaded to the local machine for Intellisense's used.

A similar question was asked here:

https://social.msdn.microsoft.com/Forums/en-US/435b4d50-53f1-4c76-a9d1-239ed47c65e8/vs-linux-project-how-to-target-different-gcc-versions?forum=vcgeneral

The answer given was to specify the compiler in the Configuration Properties -> C/C++ -> General.  But, is that only for a Visual Studio Project?  i.e. not for a CMake project?

How would I specify the compiler for a CMake project?

VS Linux Project - How to target different GCC versions?

$
0
0

Hi,

Using Visual Studio 2017, I have a C++ Linux project which currently connects to a remote Linux machine (CentOS 7)

I have both GCC 4.8.5 and GCC 7.2.1 installed on the CentOS machine

How can I instruct Visual Studio to use the GCC 7.2.1? Currently it always defaults to 4.8.5.

I have tried adding the following to the Remote Pre-Build Event:

source scl_source enable devtoolset-7

scl enable devtoolset-7 bash

export CC=/opt/rh/devtoolset-7/root/usr/bin/gcc

export CXX=/opt/rh/devtoolset-7/root/usr/bin/cpp

export CPP=/opt/rh/devtoolset-7/root/usr/bin/c++

But no matter what I try the project always builds using GCC 4.8.5.

If I log on to the Linux machine, terminal window and type "scl enable devtoolset-7 bash" followed by "gcc --version" I get "gcc (GCC) 7.2.1 20170829 (Red Hat 7.2.1-1)"

Dynamic array in Visual Stdio IDE

$
0
0

Hello,

We cannot run the below code in Visual Studio and I have an error but in othercompilerit can be compile.

What's the difference?

#include<iostream>


int main()
{
    int n;
    cin>>n;

    int a[n];

    return 0 ;
}

Load C++ DLL At Specific Range Of Address

$
0
0

I want to develop a C++ dynamic library, a DLL. It targets x64. But when the application that uses this DLL runs, I want the DLL to be loaded within range of signed 32 bit integer memory space.

How to do that?

Viewing all 15302 articles
Browse latest View live


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