|
I am trying to figure out how to use the findfirst or findfirstfile to find the first file
in a given directory.
I want to be able to find the first file that is either:
A bmp or gif or png or a jpg.
So in other words the first image file meeting any of the above four image types.
|
|
|
|
|
|
Yes, I found that but how do you search for a range of file extensions?
This only seems to either do *.* or a specific single file.
|
|
|
|
|
Well I`ll guess you`llhave to do a FindFirstfile followed by a
do - while statement where you check if the file has one of the extensions you are looking for...Something like below...
<code> TCHAR dir[] = { _T("C:\MyPath\Mypics\*.*") };
bool bFoundLegalPic=false;
WIN32_FIND_DATA findData;
HANDLE srchHandle = FindFirstFile(dir, &findData);
if(INVALID_HANDLE_VALUE != srchHandle )
{
do{
//here check last 4 chars of filename (in the finddata variable)
//with the extensions you wish to retrieve
}while(!bFoundLegalPic && FindNextFile(srchHandle, &findData));
FindClose(srchHandle);</code>
Hope this helps you...
Greets,
Davy
|
|
|
|
|
That's not the approach I ended up trying, but probably a better solution than mine.
Thanks.
|
|
|
|
|
Hi Guys,
I am trying to use the Crypt32.lib in one of my VC++ application. i am calling the CryptAcquireContext(&hCryptProv,NULL,NULL,PROV_RSA_FULL,0) function, but i get the following error
Crypt32Dll.obj : error LNK2001: unresolved external symbol _CryptAcquireContext@20
Debug/Crypt32Dll.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
can any of you guys help me on this why i get linking error.
Thank You
Regards
tuscan.
|
|
|
|
|
I've never used this dll, but I've gotten this error when I didn't have the .lib file linked in my project for whatever header I was using
My articles
www.stillwaterexpress.com
BlackDice
|
|
|
|
|
hi
i want to know the basic of network programming what things are involved in the network programming. how to make packets of files etc.
ddd
|
|
|
|
|
i use Selchanged event to trace user's selection in tree control. normally it is ok. But when user click the same item twice or more(not double click, there are some long delay between two click), windows will not call selchanged event(I think that windows think there is no change). how can i react the event like this, thank you
Happy Gemini
|
|
|
|
|
Handle the NM_CLICK notification
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
I've been battling around trying to implement WMI into my MFC application. I'm trying to get Windows XP informations such as product key, activation status, ect. I used COM init to interface with Win32_WindowsProductActivation class. I have problems with changing Windows XP Product Key. How can I run SetProductKey method with parameters??? I went through Microsoft docs but it's not clear to me at all. Any hits or sample code??? I've seen VB script but i have difficulty implementing it with C++.
Thank you all
|
|
|
|
|
Can u provide a code snippet of what you are trying to do?
Einstein: "Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe."
My Articles
|
|
|
|
|
Hi Aamir,
Thanks for your reply. I don't have problems extracting informations from
Win32_WindowsProductActivation class properties. I have problem using the class methods. In this function i'm trying to pass new product key and change existing one. Can i do it with this SetProductKey method???? or need to use Put method?? Your help is very appreciated. Also well done on that article.
void CKeyFinder::SetWinKey(char * newkey)
{
CoInitialize(NULL);
//Security needs to be initialized
if(CoInitializeSecurity( NULL,
-1,
NULL,
NULL,
RPC_C_AUTHN_LEVEL_PKT,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE,
0
) != S_OK)
return;
IWbemLocator *pIWbemLocator = NULL;
IWbemServices *pWbemServices = NULL;
IEnumWbemClassObject * pEnumObject = NULL;
BSTR bstrNamespace = (L"root\\cimv2");
if(CoCreateInstance(
CLSID_WbemLocator,
NULL ,
CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER ,
IID_IUnknown ,
( void ** ) & pIWbemLocator
) != S_OK)
return;
if(pIWbemLocator->ConnectServer(
bstrNamespace, // Namespace
NULL, // Userid
NULL, // PW
NULL, // Locale
0, // flags
NULL, // Authority
NULL, // Context
&pWbemServices
) != S_OK)
return;
HRESULT hRes;
//IWbemServices pointer to make requests of WMI
BSTR strQuery = (L"Select * from Win32_WindowsProductActivation");
BSTR strQL = (L"WQL");
hRes = pWbemServices->ExecQuery(strQL, strQuery,WBEM_FLAG_RETURN_IMMEDIATELY,NULL,&pEnumObject);
if(hRes != S_OK)
{
AfxMessageBox("Could not execute Query");
return;
}
ULONG uCount = 1, uReturned;
IWbemClassObject * pClassObject = NULL;
IWbemClassObject * piObj = NULL;
hRes = pEnumObject->Reset();
if(hRes != S_OK)
{
AfxMessageBox("Could not Enumerate");
return;
}
hRes = pEnumObject->Next(WBEM_INFINITE,uCount, &pClassObject, &uReturned);
if(hRes != S_OK)
{
AfxMessageBox("Could not Enumerate");
return;
}
CString csWin32Activation ("Win32_WindowsProductActivation");
CComBSTR bstrWin32Activation (csWin32Activation);
hRes = pWbemServices->GetObject(bstrWin32Activation,WBEM_FLAG_RETURN_WBEM_COMPLEATE,NULL,&piObj,NULL);
//get the input class for the SetProductKey method
CString csSetProductKey ("SetProductKey");
CComBSTR bstrSetProductKey (csSetProductKey);
hRes = pClassObject->GetMethod(bstrSetProductKey,0,&pClassObject,NULL);
hRes = pClassObject->SpawnInstance(0,&pClassObject);
//SetProductKey takes one argument uint32 SetProductKey(string ProductKey);
CComBSTR bstrNewKey (newkey);
VARIANT v;
VariantInit(&v);
v.vt = VT_BSTR;
v.bstrVal = (BSTR)bstrNewKey;
pClassObject->Put(L"SettingID",0,&v,0);
//Problem is here
//execute the method
// CString csObjName = bstrNamespace + csWin32Activation + "." + "
// CComBSTR bstrObjName(csObjName);
// hRes = pWbemServices->ExecMethod(bstrObjName,bstrSetProductKey,0,NULL,pClassObject,0,NULL);
//error check
if (FAILED(hRes)) {
AfxMessageBox("Could not exec SetProductKey method",hRes);
return;
}
//clean up
VariantClear( &v );
pIWbemLocator->Release();
pWbemServices->Release();
pEnumObject->Release();
pClassObject->Release();
CoUninitialize();
|
|
|
|
|
From MSDN: "This method is valid only if the ActivationRequired property is equal to 1."
Have u checked it.
Plus.. I have run your code and it fails on GetMethod call. Have a look into it again.
Another thing... Why are u trying to call SpawnInstance.
Einstein: "Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe."
My Articles
|
|
|
|
|
Dejan Kovac wrote:
I've been battling around trying to implement WMI into my MFC application....I've seen VB script but i have difficulty implementing it with C++.
See here.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Hi Dave,
Thanks for reply. You are reading data from class properties.I don't have problem with it at all. My problem is using the class methods. See Win32_WindowsProductActivation class SetProductKey method. How do I implement it??
Cheers
Dejan
|
|
|
|
|
Dejan Kovac wrote:
My problem is using the class methods.
My apologies for the confusion. Most of the questions I see regarding WMI are of the "How do I get access to it?" variety.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
I have an application that displays dialogs as pages within a property sheet. Most of the controls work fine, but I am having trouble getting an edit box with horizontal scroll to work. I have multiline set to true and horizontal scroll set to true in the properties box for the edit box control. I also have vertical scroll set to true - that works. When the dialog is activated, the horizontal bar does not show up. The vertical bar shows up and works.
I have tried to add the horizontal scroll dynamically without success. If I place the code in OnInitDialog for the dialog that has the edit control on it, the program errors out in winocc.cpp in CWnd::ModifyStyle on
<br />
ASSERT(::IsWindow(m_hWnd) || (m_pCtrlSite !=NULL)):<br />
The same happens if I place this call in the OnInitDialog for the main Dialog, after the property page has been added to the property sheet.
If I put the call to ModifyStyle in a handler for OnShowWindow, the program does not abort, but the horizontal bar does not show up. Any ideas?
Code that sets up the page in the property sheet:
<br />
dlgPropSheet.AddPage((CPropertyPage*) &msgDlg);<br />
dlgPropSheet.Create(this, WS_CHILD | WS_VISIBLE, 0);<br />
dlgPropSheet.ModifyStyleEx(0, WS_EX_CONTROLPARENT);<br />
dlgPropSheet.ModifyStyle(0, WS_TABSTOP);<br />
Code I tried both in OnInitDialog for msgDlg and right after the above code in OnInitDialog for the main dialog:
<br />
pMsgDlg->m_rawMsg.ModifyStyle(0, WS_HSCROLL);<br />
|
|
|
|
|
Hi everyone,
I am busy creating a little setup project and run into a problem when compiling the debug version into a release version. (LNK4098 linker warning)
My question is what is the difference between Single-threaded and Multithreaded CRT options in the compiler and when do I choose which one ?
(My project do spawn a second thread apart from the main running thread.)
Regards
Ramsus
Carpe Deum
|
|
|
|
|
If you're using the CRT from multiple threads, use the multithreaded version. If not, the singlethreaded version is smaller and slightly quicker.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
It depends...
Ryan gave a good answer, in ideal [single threaded] circumstances you should choose to use the single threaded crt libraries.
rules of thumb
* If there is any chance that in the future any part of the project may be multithreaded I recommend setting the options for the project to use the multi-threaded libraries. From past experience, it's easier to tell everyone else on the team what the setting should be rather than trying to let them figure it out (or change it) on their own.
* If any of your dependancies are distributed as binaries linked against a particular crt, you MUST link against the same type.
* If you don't want to distribute any .dll's with you product, statically link to the crt.
|
|
|
|
|
I have a MDI architecture.
When the application starts, it has a blank document. If I open another document and the initial doc has not changed, I would like to close it...
OR
I would like to start the application but have NO initial document open..
can you help with either one?
thanks
|
|
|
|
|
BOOL CMyWinApp::InitInstance()
{
...
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
if (!ProcessShellCommand(cmdInfo))
return FALSE;
...
} /ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
// Don't display a new MDI child window during startup,
// if there are no file arguments at the command promt.
if(cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew;)
{
cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
}
http://www.priyank.in/
|
|
|
|
|
The return value for my SetDIBColorTable() function call is 0 (zero), so the function failed . Why ?
Here's the source code :
HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemDC, m_handlerToBMP);
RGBQUAD pColors[256];
//RGBQUAD *oldpColors;
for(int i=0; i<256; ++i)
{
pColors[i].rgbRed = i;
pColors[i].rgbBlue = i;
pColors[i].rgbGreen = i;
pColors[i].rgbReserved = 0;
}
//pColors1=pColors;
//GetDIBColorTable(hMemDC, 0, 256, oldpColors);
UINT aaa=SetDIBColorTable(hMemDC,0,255,pColors);
|
|
|
|