|
I try to read all files ( path files ) from 'Recent File List' from registry , and I failed ... I try with RegEnumValue function , but this give me string values ( File1 , File2 etc. ) not path of this files... I read RegEnumValue remarks and I see that somehow , with LPBYTE lpData parameter I could have string values , but I have no ideea how to convert LPBYTE to CString or char ... and Google didn't help me ( I didn't find a sample appropiate to my request ) ... can you help me , please ... maybe you have front with this problem ... Thank you.
|
|
|
|
|
Using the RegEnumValue() [^] function returns you the name of the value (File1 etc) and the content as a byte array. It also returns you a value item in lpType which tells you what type of data the value has. Assuming you check that this is a REG_SZ (null terminated string) then you can merely cast the pointer to the appropriate type and thence handle it as required, something like:
HKEY hKey
DWORD dwIndex = 0;
char szValueName[256];
DWORD cchValueName = 256;
DWORD dwType;
BYTE bData[4096];
DWORD cbData = 4096;
RegEnumValue(hKey, dwIndex, szValueName, &cchValueName, NULL, &dwType, bData, &cbData)
LPSTR pszValue = reinterpret_cast<LPSTR>(bData);
The best things in life are not things.
|
|
|
|
|
Thank you so much , I will try your solution and let you know what I have done .
modified on Tuesday, June 21, 2011 2:52 AM
|
|
|
|
|
Up-voted - I have no idea what sort of moron would 1-vote what is a totally reasonable response to my post.
The best things in life are not things.
|
|
|
|
|
Take away bad intention from various people, you do here best job, it' always a pleasure to talk here with so many good programmers that post here from altruism. Kindly thank you.
P.S. I didn't try your code yet, catch with other things.
|
|
|
|
|
Great , does function ! Thanks again !
|
|
|
|
|
Happy to help.
The best things in life are not things.
|
|
|
|
|
I've been interested in game development and have been using C++ for the past 3 years now, as well as OpenGL just recently. But does anyone here know of a good sound API? I've seen OpenAL, which has a basic extent of features, but I'd like something a little more flexible if possible. I've also taken a look at fmod and liked the looks of it until I saw the price tags for publishing a game with it (ranged from $500 - $9000 per platform).
Thanks for any suggestions!
|
|
|
|
|
A senior C#/C++ developer asked me this question during the interview. I thought I share it with you guys.
int x= 0;
int y= 0;
thread1
{
while (x==0) { just sit here};
printf("%d",y);
}
thread2
{
y=42;
x=1;
}
He said Assume that we know for sure Thread 1 had started before thread2:
Q1) what will printf print for answer? I said 42, that was correct.
Q2) Then he said, but suppose the answer was y=0, do you know how could that happen knowing thd1 started before thd2?
I did not get the answer correct. I did think threading, mutexes,..etc it wasn't what he was trying to get at I guess! I do know the answer, but I would like to see how you might answer.
|
|
|
|
|
Well, I think, the main reason would be that because y is not marked as volatile, the compiler might have read y (into a register) before the the while loop not knowing that the variable could be modified externally.
Without that clue, I would have probably assumed that it always works... And it probably does in many cases (platform, compiler and compiler options).
Philippe Mori
|
|
|
|
|
Well his answer was that this wouldn't happen on a single processor, but would happen on multi CPU ssytems... He said that the instructions at may get out of order as the compiler might re-arrange instructions for optimization for example, so it might load x before it does y... he said this could be avoided obviously by locks which I mentioned to him, but he said that there is also this idea of "memory fence" where you tell it by some commad "asm something..", which tells the compiler to put a fence between the instructions so the instructions don't get re-arranged...
|
|
|
|
|
This is a classic case and should be something you learn to watch for in any multithreaded application.
You have multiple variables (x, y) that must be in a consistent state (when x != 0, y must have the correct value) in order for the relationship between them to be correctly interpreted.
The only way to ensure this state is to use some form of mutual exclusion around the Setter and the Tester so that both variables are looked at as a single atomic item.
As Philippe said, it might work on some platforms and some compilers but if you are ever to take your multithreaded programming skills to other platforms then you need to learn how to avoid cases like this in the general case and use the tools in the multithreaded API to control access.
|
|
|
|
|
I am not sure if you understood my post. I did answer that I would use mutex to synchrnonize and avoid wrong results. But, his question was explain how I can get the wrong result in this case and this had nothing to do with synchronization. He wanted me to see if I understood "memory fence" which I clearly never heard of to not allow instructions to be out of order while compiler optimization.
|
|
|
|
|
Like already pointed out, not declaring x and y as volatile could be a problem: the compiler might optimize away the test on x, i. e. pull it outside the loop, or it may just load x into a register and never bother to reload it from memory. In fact, since x is not declared as volatile, the compiler may feel obliged to make sure x is never reloaded from memory!
|
|
|
|
|
Thanks for the explanation, it does make sense.
|
|
|
|
|
I am in learning process:
here I am trying to create a custom control in mfc
file 1:
InserEdit.h
#pragma once
#include <afxwin.h>
#define INSERTWINDOWCLASS L"INSERTWINDOWCLASS"
class CInsertEdit :
public CWnd
{
DECLARE_DYNAMIC(CInsertEdit)
protected:
CEdit *cid,*UserName,*PhoneNumber,*DateOfBirth,*Nationalities;
BOOL PreCreateWindow(CREATESTRUCT& cs);
void PreSubclassWindow();
public:
CInsertEdit();
~CInsertEdit(void);
BOOL Create(CWnd* pParentWnd, const RECT& rect, UINT nID, DWORD dwStyle);
DECLARE_MESSAGE_MAP()
private:
BOOL RegisterWindowClass();
};
InsertEdit.cpp
#include "InsertEdit.h"
BEGIN_MESSAGE_MAP( CInsertEdit, CWnd)
END_MESSAGE_MAP()
IMPLEMENT_DYNAMIC(CInsertEdit, CWnd)
CInsertEdit::CInsertEdit()
{
RegisterWindowClass();
return;
}
BOOL CInsertEdit::RegisterWindowClass()
{
WNDCLASS wndcls;
HINSTANCE hInst = AfxGetInstanceHandle();
if (!(::GetClassInfo(hInst, INSERTWINDOWCLASS, &wndcls)))
{
memset(&wndcls, 0, sizeof(WNDCLASS));
wndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
wndcls.lpfnWndProc = ::DefWindowProc;
wndcls.cbClsExtra = wndcls.cbWndExtra = 0;
wndcls.hInstance = hInst;
wndcls.hIcon = NULL;
wndcls.hCursor = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
wndcls.hbrBackground = (HBRUSH) (COLOR_WINDOW);
wndcls.lpszMenuName = NULL;
wndcls.lpszClassName = INSERTWINDOWCLASS;
wndcls.cbWndExtra = NULL;
if (!AfxRegisterClass(&wndcls))
{
AfxThrowResourceException();
return FALSE;
}
}
return TRUE;
}
CInsertEdit::~CInsertEdit(void)
{
}
BOOL CInsertEdit::PreCreateWindow(CREATESTRUCT& cs)
{
return CWnd::PreCreateWindow(cs);
}
void CInsertEdit::PreSubclassWindow()
{
CWnd::PreSubclassWindow();
cid=new CEdit();
BOOL what=cid->Create(WS_VISIBLE|WS_CHILD|WS_BORDER,CRect(0,0,100,24),this,1);
}
BOOL CInsertEdit::Create(CWnd* pParentWnd, const RECT& rect, UINT nID, DWORD dwStyle)
{
return CWnd::Create(INSERTWINDOWCLASS,L"",dwStyle,rect,pParentWnd,nID);
}
The problem is when i run the program it triggers to debug break point. it is created in PreSubclassWindow class. on line 3 with cig->Create calling. can anyone point out what I am doing wrong?
modified on Saturday, June 18, 2011 4:57 AM
|
|
|
|
|
This is quite difficult to read. Please edit your message and replace the <code> tags by <pre> tags for correct code block formatting. you could also help by marking the line of code where your error occurs.
The best things in life are not things.
|
|
|
|
|
Thank you for your reply.
The error occur in PreSubclassWindow() function on line(I cant tell you exact Line Number) BOOL what=cid->Create(WS_VISIBLE|WS_CHILD|WS_BORDER,CRect(0,0,100,24),this,1);.
But here is some confusing issue. I have used PreSubClassWindow instead of onCreate Window message. And I also get some example that is created based on PreSubClassWindow. They failed at the same point. i.e. creating child window.
Later I changed it to onCreate and it solved my problems.
By the way I am using Visual Studio 2010
Thank you
|
|
|
|
|
Probably the function was called too soon like before the actual HWND was allocated and it was failing at a check done by MFC.
Philippe Mori
|
|
|
|
|
Hi, I've a modal dialog box and I've tried to set a bitmap background:
case WM_ERASEBKGND:
{
HDC memDC, hdc;
HBITMAP hBmp;
BITMAP bmp;
RECT rcc;
hdc = GetDC(hDlg);
hBmp = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BMP));
memDC = CreateCompatibleDC(hdc);
SelectObject(memDC,hBmp);
GetObject(hBmp, sizeof(bmp), &bmp);
GetClientRect(hDlg,&rcc);
SetStretchBltMode(hdc, HALFTONE);
StretchBlt(hdc,
0,0, rcc.right,rcc.bottom,
memDC,
0,0,bmp.bmWidth, bmp.bmHeight,
SRCCOPY);
DeleteDC(memDC);
DeleteObject(hBmp);
ReleaseDC(hDlg,hdc);
return (INT_PTR)TRUE;
}
this code set a background bitmap, but when I move or resize the dialog controls(edit,button,listbox,...) disappear under the bitmap...what's wrong?how can i repaint correctly the dialog?
|
|
|
|
|
Hi,
Try creating the window with the WS_CLIPCHILDREN window style. Also... you might be better off painting the bitmap in WM_PAINT and returning TRUE in your WM_ERASEBKGND handler to avoid flicker.
|
|
|
|
|
Please see the order if u are give the order for bitmap at the last the it will overwrite ur textbox and other things
|
|
|
|
|
Hi, I seem to remember trying this in the past, though failed miserably (presumably for the same reason) I recall using a frame based window, since I could define the background image (as a HBRUSH) in the windows class (ms class, not c++ class)
Anyhow, I just ad a few fresh ideas and seem to have resolved the issue. I'll admit I didn't try with a bmp, but since trying to paint a solid color resulted in the same behaviour, I'll (perhaps foolishly?) assume that the solution would be valid if I had.
[EDIT: yup - it works just fine with a bitmap too]
It's just a simple matter of calling InvalidateRect along with the hWnd of the dialog, the client area (or NULL for all of it) and False - for do not redraw.
I.e, just add the line
InvalidateRect(hwndDlg, NULL, false);
after you've done the clean-up and before you return true.
Something like so:
case WM_ERASEBKGND:
{
HDC memDC, hdc;
HBITMAP hBmp;
BITMAP bmp;
RECT rcc;
hdc = GetDC(hwndDlg);
hBmp = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP1));
memDC = CreateCompatibleDC(hdc);
SelectObject(memDC,hBmp);
GetObject(hBmp, sizeof(bmp), &bmp);
GetClientRect(hwndDlg,&rcc);
SetStretchBltMode(hdc, HALFTONE);
StretchBlt(hdc, 0,0, rcc.right,rcc.bottom, memDC, 0,0,bmp.bmWidth, bmp.bmHeight, SRCCOPY);
DeleteDC(memDC);
DeleteObject(hBmp);
ReleaseDC(hwndDlg,hdc);
InvalidateRect(hwndDlg, NULL, false);
return (INT_PTR)TRUE;
}
|
|
|
|
|
I am new to C++ MFC programming and -- though I've read a lot concerning the subject -- none of recipes seems to work in my case. The snippet of code is as follows:
void CPatchDlg::OnStart()
{
...
CWinApp* pApp = AfxGetApp() ;
pApp->SetRegistryKey(lpszRegistryKey) ;
}
Function SetRegistryKey(lpszKey) is a protected member of CWinApp class and cannot be used directly:
error C2248: 'SetRegistryKey' : cannot access protected member declared in class 'CWinApp'...
Please, help me to work around the problem.
|
|
|
|
|
what you are trying to achieve?
|
|
|
|
|