|
Perhaps you should read the docs pertaining to the redistritubals for your compiler/SDK. Sometimes distributing a single dll is not permitted, the whole installer must be distributed instead.
This is the case with DirectX, you cannot distribute a single 3mb dll, you must send the 40mb installer or provide a weblink ( the installer will download and install ).
|
|
|
|
|
One upon a time, in a galaxy far away, before an evil empire consumed all the protoculture on earth, you could statically link MFC to your Visual C++ application so you wouldn't have to worry about which dll's (except GDI+ on pre-XP boxes of course) you needed to send out the door with your app.
It used to be in the Project settings/properties in VC++ 6.0 and 2003.
Please tell me the children of the shadow did not remove that option from VC++ 2005. I'm still struggling with them cancelling Paul DiLascia's "C++ At Work" articles and I don't think I can take much more of this assimilation.
Does the option to statically link still exist on 2005?
|
|
|
|
|
|
I'm trying to find a good way to programmatically prevent a user from switching to, or gaining focus on, a specific application.
I have an appication which writes large files. These are intended to be used by another application.
This "Other Application" is a large elaborate system, and one of the things it does is monitor a particular directory, continuously updating its own status about the contents of that directory.
This is the directory which my application would also like to write.
If this App is allowed to monitor this directory at the same time my app is writing to it there will be trouble, including potential lost of data, deadlock, or crash.
If this App is running, but does not have focus, it's monitoring stops, so my application can write to the "shared" directory as long as the user does not switch back to this other App.
So, I would like to prevent the user from switching to it (while allowing any other action). I've thought of a few ways to attempt this -
A) Inject code into the other app and hook its message loop (I don't really want to do it that way, as it risks creating instability).
B) Hook the desktop and trap user messages which would wake that App up (but I'm not exactly sure how to go about this).
C) Use SuspendThread() and ResumeThread() to turn it off and on.
Does anyone have suggestions or ideas about how to accompish this?
Thanks.
(If there is a better discussion area for this topic, please let me know)
Brooks
|
|
|
|
|
Why don't you just hide that window while you are writing to the directory. It would be impossible for the user give it focus that way.
|
|
|
|
|
This would make the hidden application disappear - the user might not like this (I wouldn't). Also, I'm not sure if "hidden" would prevent a switch via Alt-Tab or Task Manager.
Ideally the user would find his mouse select, Alt-Tab, or Task Manager "Switch To" would not work on that App, and it would be nice to report that "Use of this Application is temporarily blocked by the OtherApp".
-Brooks
Brooks
|
|
|
|
|
I believe I've found a solution.
The following appraoch will find the Apps window, minimize it, and suspend the Apps threads. The user can't reach the App by mouse, Alt-Tab, or Task Manager.
On resume, its all restoreed.
//////////////////////
By enumnerating the desktop windows ( EnumDesktopWindows() ) and searching for the App's registered class name ( GetClassName())in the Enum CallBack one can find the application Window.
Its a good idea to minimize the App before suspending
( ::ShowWindow(m_hwndSuspended, SW_MINIMIZE);)
so the user does see the unpainted app
GetWindowThreadProcessId() will give the process ID. Open it:
m_hProcessSuspended =
OpenProcess(PROCESS_ALL_ACCESS ,FALSE, m_dwProcessIdSuspended) ;
//////////////////////
Now suspend the thread - credit for this approach goes to
// File Name: AdvancedTaskManagerDlg.cpp
// Contents : Implementation of AdvancedTaskManagerDlg class.
// Originator: Madhu Raykar.
See -
CAdvancedTaskManagerDlg::PauseResumeThreadList() of AdvancedTaskManagerDlg.cpp
This version is slightly modified :::
BOOL CAdvancedTaskManagerDlg::PauseResumeThreadList(DWORD dwOwnerPID, bool bResumeThread)
{
HANDLE hThreadSnap = NULL;
BOOL bRet = FALSE;
THREADENTRY32 te32 = {0};
// Take a snapshot of all threads currently in the system.
hThreadSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
if (hThreadSnap == INVALID_HANDLE_VALUE)
return (FALSE);
// Fill in the size of the structure before using it.
te32.dwSize = sizeof(THREADENTRY32);
// Walk the thread snapshot to find all threads of the process.
// If the thread belongs to the process, add its information
// to the display list.
if (Thread32First(hThreadSnap, &te32))
{
do
{
if (te32.th32OwnerProcessID == dwOwnerPID)
{
HANDLE hThread = OpenThread(THREAD_SUSPEND_RESUME, FALSE, te32.th32ThreadID);
if (bResumeThread)
{
// cout << _T("Resuming Thread 0x") << cout.setf( ios_base::hex ) << te32.th32ThreadID << '\n';
ResumeThread(hThread);
}
else
{
// cout << _T("Suspending Thread 0x") << cout.setf( ios_base::hex ) << te32.th32ThreadID << '\n';
SuspendThread(hThread);
}
CloseHandle(hThread);
}
}
while (Thread32Next(hThreadSnap, &te32));
bRet = TRUE;
}
else
bRet = FALSE; // could not walk the list of threads
// Do not forget to clean up the snapshot object.
CloseHandle (hThreadSnap);
return (bRet);
}
//////////////////////
// be usre to resume and restore the App
if(m_dwProcessIdSuspended && m_hProcessSuspended != NULL)
{
BOOL bRet= PauseResumeThreadList(m_dwProcessIdSuspended, TRUE);
BOOL bRetShow = ::ShowWindow(m_hwndSuspended, SW_RESTORE);
m_hwndSuspended = NULL;
CloseHandle(m_hProcessSuspended);
m_hProcessSuspended = NULL;
m_dwProcessIdSuspended = 0;
}
//////////////////////
-Brooks
Brooks
|
|
|
|
|
My appologies, I made a mistake.
The BOOL PauseResumeThreadList() function comes from Daniel Turini's Why pause and resume processes? project -
http://www.codeproject.com/threads/pausep.asp
The credit for the suspend/resume approach goes to Daniel.
I used Madhu Raykar's advanced task manager as a starting point for my experiments -
http://www.codeproject.com/system/advancedtaskmanager.asp
This was also very helpful in the invetigation.
-Brooks
Brooks
|
|
|
|
|
I am a beginner at C++ but hope to get quite good and go into software development. I am trying to make a clock in c++. I use Dev-C++. Does anyone have a tutorial for clock in Dev-C++, everthing i found on here is for MS Visual C++.
Thanks in advance.. it is really appreciated!
~Adam
|
|
|
|
|
Is your clock SDL, OpenGL, DirectX/Direct3D, analog/digital, etc? Dev-C++ is WxWidgets library for the UI, but otherwise utilizes other open graphics libraries that are available for any compiler.
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|
VC 2005 Express Edition does not support MFC, however, it IS a very good standards compliant compiler, it's free, and you'll find tons more help for it.
I recommend buying a beginner book on C++ ( core C++, the standard language, not MFC or any other library ), working through it, trying to complete your task yourself, and asking specific questions when you get stuck. A tutorial will TELL you how to write your program, that's not the way to learn.
Good luck, I did the same thing about 7 years ago, and while I no longer use C++, I have succeeded in making a career out of my hobby.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I am confused how to get mutex locks to work correctly. As part of my testing I wrote the following code:
HANDLE hMutex = CreateMutex(NULL, FALSE, "ABC");
int result = WaitForSingleObject(hMutex, INFINITE);
int result2 = WaitForSingleObject(hMutex, INFINITE);
The first line creates a mutex, then the next line "locks" the mutex, then the next line waits for and tries to relock the mutex. It seems to me that the second Wait should never return (since the Mutex is already locked.) However, both Waits return immediately with the return code 0 (== WAIT_OBJECT_0).
What am I missing?
|
|
|
|
|
Your first line creates a mutex and your current thread owns it. Your current thread will continue owning it until you call ReleaseMutex(). In your second thread, WaitForSingleObject() will wait until the first thread calls RealeaseMutex(), after the first thread has released it, the second thread will own it. If the first thread wants to own it again, it must wait until the second thread releases it. understand?
It doesn't work in your example because it's all in the same thread.
|
|
|
|
|
Yes, I get it, I tried in a separate thread and it works as expected. Thanks for your help.
|
|
|
|
|
|
I'm unable to find a simple api call to get the current display settings of a particular monitor? Is there an easy way to do this or do I have to enumerate them?
|
|
|
|
|
|
Thanks for the link. Using GetDeviceCaps still involves enumerating the monitors to get a hold of the DC, or get a hold of the device name to create an IC with.
I realised there was no simple way to do what I wanted, so I put a class together to enumerate the displays and get the info through EnumDisplaySettings. The only trouble I'm having is getting ahold of a HMONITOR. I can get it from a HWND, POINT and even a RECT, but not from a device ordinal :/
|
|
|
|
|
Does anybody know of a good direct3D programing forum? I suggested CP create one about a month ago but it has yet to happen, and I have noticed that not many of the C++ forum users have an in depth knowledge of Direct3D. So I'm hoping maybe one or two of the users here have a programing site or two stored in their favourites that they know to tailor for D3D developers.
|
|
|
|
|
|
Hi,
I created a MFC AppWizard dll(MFC Extension dll) with a single function which i have defined in Export section of .def file. The function has only 2 parameters:HWND and CString. I'm calling the dll from an application. The function executes well and gives the expected result. But when i come out of the function, I'm getting exception:
"The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling
convention".
I tired giving _MSWIN_ and _WIN32 in C/C++ tab. But it is not working. The dll uses CxImage downloaded from codeproject.
What could be the problem?
Thanks & Regards,
Sanju.
|
|
|
|
|
It is because the part that call your function doesn't have the same calling convention as the one of your function. You are probably calling the function from a VB program right ?
To solve the issue, simply add a __stdcall before your function.
void __stdcall MyFunction();
See here[^]
|
|
|
|
|
Hi ,
Thank you. It worked.
The calling application also was MFC appln.
Thanks & Regards,
sanju.
|
|
|
|
|
i have put listview in my one child window when i click on the listitem it will open new window(showwindow).
but the window i got is not updated why ?
how can i update ?
please refer the follwoing code.
well i have put the UpdateWindow(hwndTagEditorDlg); but its not working what should i do?
1)
LRESULT CALLBACK GlobaListProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
.
.
.
.
case WM_NOTIFY:
{
.
.
.
.
if(((LPNMHDR)lParam)->code == NM_CLICK)
{
iSelect=SendMessage(hList,LVM_GETNEXTITEM,-1,LVNI_FOCUSED);
if(iSelect==-1)
{
break;
}
index=iSelect;
ShowWindow(hWndinoutfiledir,SW_HIDE);
ShowWindow(hwndEncrypt,SW_HIDE);
//Hide File Split window.
ShowWindow(hwndSplit,SW_HIDE);
//Hide encoder window.
ShowWindow(hwndUpload,SW_HIDE);
ShowWindow(hwndTagEditorDlg ,SW_SHOW);<br />
UpdateWindow(hwndTagEditorDlg);
}
}
//on the click of the item the new widnow proc is here it should display all the empty control but it didn't
LRESULT CALLBACK TagEditorProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
Utility util;
switch(message)
{
case WM_INITDIALOG:
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_SAVE_TAG:
_ResideId3TagForSelectedFile(hDlg);
MessageBox(hDlg,_T("You file has been saved"),_T("encoder"),0);
break;
}
break;
}
return FALSE;
}
void _ResideId3TagForSelectedFile(HWND hDlg)
{
//std::vector multiset <string,string,string,string,string,string,string,string,string,string> TAG3 t; //it is now class
//TagEditor _ProtectSet[MAX_PATH]; //it's made global
static int i=0;
Utility util;
TCHAR buff[MAX_PATH];
ListView_GetItemText(hList,index,0,(LPWSTR)&buff,MAX_PATH);
std::wstring buff_input(buff);
std::string compare(buff_input.begin(),buff_input.end());
WCHAR w_Artist[MAX_PATH],w_Title[MAX_PATH],w_Album[MAX_PATH],w_Year[MAX_PATH],w_Copyright[MAX_PATH],w_Author[MAX_PATH];
WCHAR w_Gener[MAX_PATH],w_Desc[MAX_PATH];
string str_Artist,str_Title,str_Album,str_Year,str_Copyright,str_Authour,str_Gener,str_Desc;
GetDlgItemText(hDlg,IDC_EDIT_ARTIST,w_Artist,MAX_PATH);
GetDlgItemText(hDlg,IDC_EDIT_TITLE,w_Title,MAX_PATH);
GetDlgItemText(hDlg,IDC_EDIT_ALBUM,w_Album,MAX_PATH);
GetDlgItemText(hDlg,IDC_EDIT_YEAR,w_Year,MAX_PATH);
GetDlgItemText(hDlg,IDC_EDIT_COPYRIGHT,w_Copyright,MAX_PATH);
GetDlgItemText(hDlg,IDC_EDIT_AUTHOR,w_Author,MAX_PATH);
GetDlgItemText(hDlg,IDC_EDIT_GENRE,w_Gener,MAX_PATH);
GetDlgItemText(hDlg,IDC_EDIT_DESCRIPTION,w_Desc,MAX_PATH);
str_Artist=util.ConvertWCHARToString(w_Artist);
str_Title=util.ConvertWCHARToString(w_Title);
str_Album=util.ConvertWCHARToString(w_Album);
str_Year=util.ConvertWCHARToString(w_Year);
str_Copyright=util.ConvertWCHARToString(w_Copyright);
str_Authour=util.ConvertWCHARToString(w_Author);
str_Gener=util.ConvertWCHARToString(w_Gener);
str_Desc=util.ConvertWCHARToString(w_Desc);
//this will stored values in the object _ProtectSet[i++].Exchangedata(index,compare,str_Artist,str_Title,str_Year,str_Album,str_Copyright,str_Authour,str_Gener,str_Desc);
}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
2)i would like to ask you the second thing i read the xml file in which it will display
all the tags(bascially xml values related with Edittextbox) when user click on the listitem.
where should i intialize the object of that class first time when application load and put the data which i have fetch from the XML file.
so when user click on the old file which already display in the listview which is also fecth from xml file. it will also show the tags as respectively.
if nessary i will Ready to justify the xml file
|
|
|
|
|
I am currently working on a Pioneer Robot, and I would like ton install a gps receiver on it. I want to work with the Holux GPS receiver (211 series), which is an USB one. But I am not a programmer and I absolutely don't know how to communicate with it. I work under Linux and i would like to initialize the receiver, communicate with it and gather data from it (position, speed, etc). Maybe could one of you help me with my problem, giving me a C++ code that I could use, or a website link on which I could find what I am looking for.
I thank you in advance (and please excuse my english, but I am French ).
A. G.
|
|
|
|
|