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

Need a help for oplock request and oplock break using VC++ code

$
0
0

I am using following function to request oplock but how should I know that I acquired oplock properly??

void GetOplock()
{
HANDLE FileHandle;
REQUEST_OPLOCK_OUTPUT_BUFFER Response;
BOOL bSuccess = FALSE;
BOOL ResultValid = TRUE;
DWORD PartialCheckSum = 0;
DWORD BytesSummedCounter = 0;
HANDLE KeyEvents[2];
OVERLAPPED ReadOverLapped;
LARGE_INTEGER Offset = { 0 };
DWORD RetVal;


//
// Open the file for Asynchronous I/O
//

FileHandle = CreateFile(FilePath,
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
NULL);

if (INVALID_HANDLE_VALUE == FileHandle) {
_tprintf(_T("Error 0x%x Opening %s\n"), GetLastError(), FilePath);
return;
}


ResetEvent(OplockInfo->OverLapped.hEvent);

bSuccess = DeviceIoControl(FileHandle,
FSCTL_REQUEST_OPLOCK,
&OplockInfo->Request,
sizeof(OplockInfo->Request),
&Response,
sizeof(Response),
NULL,
&OplockInfo->OverLapped);


if (bSuccess == FALSE && ERROR_IO_PENDING == GetLastError()) 
{
_tprintf(_T("got op"));
return;
}

if (bSuccess || (ERROR_IO_PENDING != GetLastError())) 
{
_tprintf(_T("We failed to acquire the oplock, the error code was 0x%x\n"), GetLastError());
CloseHandle(FileHandle);
return;
}
}

I am also using wireshark to check oplock state but not getting oplock state

It is humble request that please give me the proper suggestion to request oplock at user level.

plz provide sample code if possible.

 

Receving data on socket

$
0
0

I had asked a question about recvfrom() call earlier in this forum  Thanks for the response. I have another issue with UDP socket. Against a sendto() request of size x, my udp application receives y bytes of data on asynchronous ReadFile() socket call. When this ReadFile() completes, GetOverlappedResult() returns first x byes. I understand that the initial amount of data that can be read is the same as the size of data sent. So far it is OK.

But when I try to get the remaining amount of data using recvfrom() call, it blocks.Below is the skeleton of how I am reading the data.

unsigned long ulen = 0;

int ret = GetOverlappedResult ( ( HANDLE ) socket, overlap_socket, &ulen, FALSE );
char buff[1000000];

// get the initial x amount of data to buff. This is OK

// try reading the subsequent data
size_t buflength = y - x;
int size = recvfrom( socket, buff + x, bufflength, 0, .... ); // blocks here

Hope my question makes sense. What could be wrong here?


Detect a virtual printer on all installed local printers

$
0
0

Hello, I'd like to detect a virtual printer on all installed local printers.

i've googled a lot and finally got all lists of local printers from EnumPrinters, PRINTER_INFO_2 struct.

but i don't how to distinguish between a virtual printer and a real printer( physical printer)

can you please tell me how to detect it ?

thanks.

Tool for migration from Visual C++ 6.0 to Visual Studio 2015

$
0
0

I have an MFC application that I built with Visual C++ 6.0 and I'd like to migrate it to Visual Studio 2015.

Is there any tool for same ?

Upgrade Visual C++ 6.0 to Visual Studio 2015

$
0
0

I have an MFC application that I built with Visual C++ 6.0 and I'd like to upgrade it to Visual Studio 2015.

I have tried to open .dsw file using Visual Studio 2015.

It asked me for conversion at the time of opening. I was proceed with conversion option.

After successful conversion I tried to build same, but give me error with error no C1083. Cannot open include file ‘stdafx.h’.

I checked in project files the header file was present there.

Is there any additional setting other than include file path and library path ?

How delete folders and subfolders using a kernel driver (.sys)?

$
0
0

I had done a "Hello Word" example for test the funcionality of a kernel driver and is working very fine.

My environment of development is:

  • Computer ( VirtualBox ): Windows 7 Ultimate x86
  • Visual Studio 2010 Professional (installed in VBox)
  • Visual DDK 7.1 (installed in VBox)
  • WinDDK 7.1 (installed in VBox)

But my main goal with this kernel driver ( in this moment ) is delete folders and yours subfolders.

I saw in this link a function that seems work, but already saw in some place on web someone saying something like: "functions to kernel drivers are differents of functions used in a software "user mode" ".

So, i want know what i can use to create a code for function that i'm needing?

Thanks by any suggestion.

how to limit the number of string in an input

$
0
0

Hi, I am using _T("AAA"), but it only allows 3 characters, I want to 6 characters, how could I do that.

how to change hexadecimal color code to RGB in C++

$
0
0
is there anyway to convert the hexadecimal code to RGB code in C++?

split hex string into 3 integer in C++

$
0
0
Is there any sample to split hex string into 3 integer in C++, I got this error "Error 34 error C2102: '&' requires l-value "
	CString fontColor = CSMPLocalSettings::GetFontColor();
	int number = (int) strtol( &fontColor[1], NULL, 16);
	int r = number >> 16;
    int g = number >> 8 & 0xFF;
    int b = number & 0xFF;

TreeView windows 10 style

$
0
0

Guys,

What style am I supposed to set on treeview (mfc) in order for it to look like the one in file explorer in windows 10?

Thank you

Debugging a dll

$
0
0

My dll program works very well, thanks to the generous advice from members of this forum.  Here is my newest problem:

The user will have the release version of my app and a sample dll project that he can customize.  Is it possible to get the debugger to step through his code?  I have tried running the app and attaching it in the VS debug dialog.  The app loads the dll, which is the debug version, but I cannot trigger a breakpoint there when it runs.  I hope this is clear.

Is that possible?  What is the sequence?

DD

change dialog backgournd color and the text color at the same time

$
0
0

Hi, can we change dialog backgournd color and the text color at the same time? it looks like it returns one brush at a time. I have to return either hbr or br

HBRUSH TopBar::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

	if (pWnd->GetDlgCtrlID()==IDC_STATIC_TEXT)
	{
		pDC->SetTextColor(RGB(r,g,b));
	}



	pDC->SetBkColor(RGB(51, 255, 153));
    static CBrush br(RGB(51, 255, 153));

	return (hbr);
}

Dialog based MFC exe not being able to run!!

$
0
0

Hi,

I have an MFC exe that is dialog based, but that for some reason (don't know what I changed) it is not being able to DoModal().

On the application's InitInstance() this happens:

	CGridCtrlDemoDlg dlg;
	m_pMainWnd = &dlg;
	INT_PTR nResponse = dlg.DoModal();
	if (nResponse == IDOK)
	{
	}
	else if (nResponse == IDCANCEL)
	{
	}

	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;

nResponse returns IDCANCEL.

On the creation of the CDialog, MAKEINTRESOURCE(nIDTemplate) returns a pointer which does not allow to read the charatacters...

So, it might be a resource problem??

Can I share it in OneDrive?

Regards,

Juan


Juan Dent

GDI+ object resource leak

$
0
0

Hi,

In my MFC cad code, I have the following lines that cause Task Manager GDI Object count to go up, until 9,999 and the program crashes. The CloseHandle below does not seem to work. What else do I need to do to prevent GDI+ resource leak?

Thank you

Gdiplus::Region reg(,,,,,);

Gdiplus::Graphics g (m_hDC);
HRGN hClip = reg.GetHRGN(&g );
g.SetClip(hClip);
CloseHandle(hClip);

MFC Library source code and Fluent UI licensing program

$
0
0

Hi,

I'm considering using part of MFC source code in our commercial software. For instance: AfxRibbonStatsBar.cpp file. The code would obviously be modified to suit the purpose of the application. however, these below lines are noted. 

// This MFC Library source code supports the Microsoft Office Fluent User Interface 
// (the "Fluent UI") and is provided only as referential material to supplement the 
// Microsoft Foundation Classes Reference and related electronic documentation 
// included with the MFC C++ library software.  
// License terms to copy, use or distribute the Fluent UI are available separately.  
// To learn more about our Fluent UI licensing program, please visit 
// http://go.microsoft.com/fwlink/?LinkId=238214.
//
// Copyright (C) Microsoft Corporation
// All rights reserved.

But when i go to URL http://go.microsoft.com/fwlink/?LinkId=238214, the page show it's retired ? What does it mean ? How can i get official information about Fluent UI licensing program ?

It would be nice if someone affiliated with Microsoft could respond to this post.


How long can IStorage holds its data when using STGM_SHARE_EXCLUSIVE

$
0
0

Hi,

I have the following two lines of code.  After pStorage is out of scope, can others start to open the "Data" storage with STGM_SHARE_EXCLUSIVE?  In other words, how long can pStorage holds "Data" in the exclusive mode?  I suppose that it holds "Data" until pStorage is released.  Is it correct?  Thanks.

  CComPtr<IStorage> pStorage;
  hr = p3rdPartyStorage->OpenStorage(_T("Data"), NULL, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, NULL, 0,  &pStorage);

JD

unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup

$
0
0

hey, i dont know what to do, i have subsytem :  Windows (/SUBSYSTEM:WINDOWS)

i will be grateful for any help ...

i have errors :

fatal error LNK1120: 1 unresolved externals and

unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup

here is a part of my code, i dont know where i should  look for these errors?

#pragma once
#include "magazyn.h"
#include <math.h>
namespace wahadlo {

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

    /// <summary>
    /// Summary for MyForm1
    /// </summary>
    public ref class MyForm1 : public System::Windows::Forms::Form
    {
    public:
        magazyn* m;

        MyForm1(void):m(new magazyn)
        {
            InitializeComponent();
            //
            //TODO: Add the constructor code here
            //
        
                
        }
    private: System::Windows::Forms::TextBox^  textBox4;
    private: System::Windows::Forms::DataVisualization::Charting::Chart^  chart1;
    private: System::Windows::Forms::Label^  label5;
    private: System::Windows::Forms::Label^  label6;
    private: System::Windows::Forms::TextBox^  textBox5;
    private: System::Windows::Forms::Label^  label7;
    private: System::Windows::Forms::Label^  label8;
    private: System::Windows::Forms::TextBox^  textBox6;
    private: System::Windows::Forms::Label^  label9;
    private: System::Windows::Forms::Label^  label10;
    private: System::Windows::Forms::Label^  label11;
    private: System::Windows::Forms::TextBox^  textBox7;
    private: System::Windows::Forms::TextBox^  textBox8;
    private: System::Windows::Forms::TextBox^  textBox9;
    private: System::Windows::Forms::ComboBox^  comboBox1;
    private: System::Windows::Forms::CheckBox^  checkBox1;
    private: System::Windows::Forms::Label^  label12;






    public:
        
    //magazyn* m = new magazyn;

    protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~MyForm1()
        {
            if (components)
            {
                delete components;
            }
        }
    private: System::Windows::Forms::Label^  label1;
    protected:
    private: System::Windows::Forms::Label^  label2;
    private: System::Windows::Forms::Label^  label3;
    private: System::Windows::Forms::TextBox^  textBox1;
    private: System::Windows::Forms::TextBox^  textBox2;
    private: System::Windows::Forms::TextBox^  textBox3;
    private: System::Windows::Forms::Button^  button1;
    private: System::Windows::Forms::Label^  label4;

    private:
        /// <summary>
        /// Required designer variable.
        /// </summary>
        System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents o

Unexpected error placing data into a CEdit control

$
0
0

Hi,

I have a CPropertyPage dialog, with a CEdit control, and it if failing with an exception when I put data into it. The CEdit control has "Number" set to true in its Properties, text centered and all other values set to their standard defaults.

During the OnInitDialog function I obtain the current value for an "int" variable, and use the the following code to update the CEdit control:

    if (m_nHeightModifier == 0)
    {
        m_edHeightModifier.Clear();
    }
    else
    {
        szString.Format(_T("%i"), 15); // This value works
        szString.Format(_T("%i"), 13); // This value works
        szString.Format(_T("%i"), 12); // This value fails
        m_edHeightModifier.SetWindowText(szString);
    }
    return;

The szString.Format show different values I have hardcoded for testing. With the values of 15 and 13 the code worked. WIth a value of 12 or below the code fails.

Many thanks in advance

How can I request a value and wait for the value to be returned via MFC socket classes but not using http?

$
0
0

I have an arduin microcontroller connected to my home network and it is running a UDP server.

I can successfully send data to it, using CAsynchSocket, and I can confirm it received by the microcontroller.

But there seems to be no way I can use this class to receive data back from the microntroller immediately after the request.

In fact the data arrives some time after my requesting function exits - which is useless.

I can't use any blocking loops in my requesting function because that prevents virtual void OnReceive(int nErrorCode) from being called and the data from the microcontroller will never arrive while the loop is running.

I am trying to use this to send small files between windows app and the micro controller - I can't use ftp with this micro controller

MFC, how to let resize child window when the parent window moves

$
0
0
I am trying to resize child dialog when the parent dialog moves, but I can not get the child dialog handle from the parent dialog, here is the my code,
void CMFCTestDlg::OnSize(UINT nType, int cx, int cy)
{
	CDialogEx::OnSize(nType, cx, cy);
		//if (m_test->GetSafeHwnd())
		//	m_test->MoveWindow(0, 0, cx, cy);
	if (nType != SIZE_MINIMIZED)
	{
		ChangeSize(IDD_DIALOG1, cx, cy);
		GetClientRect(&m_rect);
	}



	// TODO: Add your message handler code here
}

void CMFCTestDlg::ChangeSize(UINT nID, int x, int y)
	CWnd *pWnd = GetDlgItem(IDD_DIALOG1);
      if (pWnd->m_hWnd){
		CRect rec;
		pWnd->GetWindowRect(&rec);
		ScreenToClient(&rec);
                rec.left = rec.left*x / m_rect.Width();
		rec.top = rec.top*y / m_rect.Height();
		rec.bottom = rec.bottom*y / m_rect.Height();
		rec.right = rec.right*x / m_rect.Width();
		pWnd->MoveWindow(rec);
	//}
}

Viewing all 15302 articles
Browse latest View live


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