|
This has been bugging me. What I was thinking of was DrawFrameControl(). Check it out to see if it helps you any. The situation I used it for didn't care about graphic prettiness or themes. I seem to recall that there was some issue in using it where that was important.
CDC::DrawFrameControl[^]
and
DrawFrameControl[^]
The link from the first page to the second is broken on the MS website, but you need info from the second to use this.Please do not read this signature.
|
|
|
|
|
Hi,
I have various builds of a DLL, depending on the target platform and I would like to be able to modify the 'Comments' item of the VERSIONINFO structure depending on the build. This would allow me to see which version of the DLL the end user has on their system. (I have had occasions where they have unknowingly copied the wrong DLL for their platform). The DLL name is deliberately identical so that the parent application does not need modification for different platforms (thats the whole idea of the DLL!).
Is there an easy way to have conditional values in the VERSIONINFO?
I have considered using Resource Hacker in the post-build step but its not clear how this can be used to modify the version info with commad line options.
Thanks
Tony
|
|
|
|
|
You can use #if and #endif in your resource script to select different entries. Then just #define the appropriate variable for each build.txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Hey, thanks for the reply!
If I remember correctly, I tried this but even with a batch full build, the compiler appeared only to compile the resources once so all of the builds had the same comment.
I can't be 100% sure that this is what happened but I will check.
Tony
|
|
|
|
|
Yes I missed that, you may need to add some extra dependencies to the project, or a pre-build statement of some sort. txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Each build will compile the .rc to a build specific .res.
Within the IDE go to Resource View.
Open the .rc file and add/select a Version.
Right-click on the Version and select Properties.
Edit the Condition field....cmk
The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.
- John Carmack
|
|
|
|
|
The question is how function-level statics are constructed when the function is called on multiple threads?
Problem Description: Deadlock occurs and my application doesn't get terminated. During initialization of local static variable it tries to acquire MSVCR80!_lock and never gets hold on the lock.
Below is the calls stack and you will see that it will never get hold on the lock _mlock
(_EXIT_LOCK1); //C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\crt0dat.c
ntdll!RtlpWaitForCriticalSection+0x132
ntdll!RtlEnterCriticalSection+0x46
MSVCR80!_lock+0x2e MyDLL!_onexit+0x36 [f:\sp\vctools\crt_bld\self_x86\crt\src\atonexit.c @ 103] MyDLL!atexit+0x9 [f:\sp\vctools\crt_bld\self_x86\crt\src\atonexit.c @ 127] MyDLL!__DllMainCRTStartup+0x7a [f:\sp\vctools\crt_bld\self_x86\crt\src\crtdll.c @ 498] MyDLL!_DllMainCRTStartup+0x1d [f:\sp\vctools\crt_bld\self_x86\crt\src\crtdll.c @ 462] ntdll!LdrpCallInitRoutine+0x14
// Code snippet below
void main()
{
atexit(MyCallBack);
exit(0);
}
void MyCallBack()
{
// Waitingforsingleobject() // Waits until all threads are terminated
}
The EXE call DllMain with DLL_THREAD_DETACH flag and we have an explicit handling as shown below
BOOL APIENTRY DllMain( HANDLE, DWORD dwReason, LPVOID )
{
if(dwReason == DLL_THREAD_DETACH)
{
F1();
F2();
}
}
F1()
{
const static CComBSTR bstrMethod = __ FUNCTION __ ;
}
F2()
{
const static CComBSTR bstrMethod = __ FUNCTION __ ;
}
Is it thread safe to have local static initialization within a function. Also I noticed if static variable is once initialized before the exit() of main application I don't see any problem. Can any one please explain what might be issue?
Note: But when I make static variable as non static the deadlock doesn't occur and problem is solved.
Also let me know any alternate solution which might help in this situation Eagerly waiting for reply.irfan
|
|
|
|
|
In general a function that uses a local static variable is generally NOT reentrant. A function that is not reentrant is not thread-safe. It isn't merely deadlock, it can also produce bad results.
There is a different instance of an automatic variable for each invocation of a function, but all invocations share one and the same local static. Access to a shared resource from threads needs concurrency control.
In your case you are talking about a const variable. In this case, it shouldn't be a problem except during initialization. Further, the run time library seems to be putting in some concurrency control for what you are doing. This concurrency control is for a different issue and would probably not be adequate for your situation. It did get me to stop and take a broader look at your situation.
You are trying this in DLLMain. You really need to carefully read the documentaiion on DLLMain[^].
In particular:
Warning There are serious limits on what you can do in a DLL entry point.
and
Unfortunately, there is not a comprehensive list of safe functions in Kernel32.dll.
and
Calling functions that require DLLs other than Kernel32.dll may result in problems that are difficult to diagnose.
and
DLL notifications are serialized
The bottom line seems to be that you are getting too fancy for DllMain. I'd suggest thinking about your design and trying to keep DllMain as bare bones and simple as possible.Please do not read this signature.
|
|
|
|
|
CritSec ntdll!LdrpLoaderLock+0 at 7c97e178
LockCount 0
RecursionCount 1
OwningThread 1998
EntryCount d
ContentionCount d
* Locked
CritSec MSVCR80!__app_type+94 at 781c3bc8
LockCount 1
RecursionCount 1
OwningThread 9a8
EntryCount 1
ContentionCount 1
* Lockedirfan
|
|
|
|
|
Hi
I want to kill a process which is running in the memory. I can get its handle by using:
HWND FindWindow(
LPCTSTR lpClassName,
LPCTSTR lpWindowName
);
What function can I use to kill the running process?
Thanks,
|
|
|
|
|
You could PostMessage(hFoundWindow, WM_CLOSE, 0, 0);
...but it is not killing,
the process code may have an own translating of the message,
for example - a question "Are you sure ?" Check your definition of Irrationality[ ^]
1 - Avicenna
5 - Hubbard
3 - Own definition
|
|
|
|
|
We use a couple of different functions to do it (probably over-kill) :
Use CreateToolhelp32Snapshot to get a snapshot of the current processes.
After that loop over the entries with Process32First and Process32Next and fetch the name of the process in the PROCESSENTRY32 structure.
And find the process in the list, use TerminateProcess with the handle in the PROCESSENTRY32 struct.
Good luck.Watched code never compiles.
|
|
|
|
|
#include windows.h
#pragma comment(lib,"Kernel32.lib")
#pragma comment(lib,"user32.lib")
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pszCmdLine, int cmdShow)
{
HWND hWnd = ::FindWindow(NULL,"Calc");
HANDLE hProcess;
DWORD dwPid;
if(hWnd)
{
GetWindowThreadProcessId(hWnd,&dwPid);
hProcess = OpenProcess(PROCESS_ALL_ACCESS|PROCESS_QUERY_INFORMATION ,FALSE,dwPid);
if(hProcess)
{
BOOL bRet = TerminateProcess(hProcess,0);
if(bRet)
{
MessageBox(NULL,"Terminate Process successed !",NULL,NULL);
}
}
}
return 0;
}
|
|
|
|
|
Well, Three answers, two using TerminateProcess, one using PostMessage. The latterone may not terminate, the former one can leave DLL's in an indeterminate state. Why not do as Microsoft does: Try Post Message, run a Progress Dialog for say 30 Seconds to see does it terminate, and if it does not, use TerminateProcess().
If the apps you want to terminate are all your own, you can include a special Message Handler for your own windows message: WM_TERMINATE_MY_PROCESSES, and post them to your apps.
Regards,
Bram van Kampen
|
|
|
|
|
#include<stdio.h>
#include<stdlib.h>
struct sorty{
int xv;
int yv;
int dir;
struct sorty * next;
}*sy=NULL;
void sort(struct sorty *curr , int x , int y , int d)
{
struct sorty * temp1 , * temp2;
temp1 = sy;
printf("asdf\n");
if(sy == NULL){
curr->xv = x;
curr->yv = y;
curr->dir = d;
curr->next = NULL;
sy = curr;
}
else{
if (sy->yv >= y){
printf("a\n");
curr->xv = x;
curr->yv = y;
curr->dir = d;
curr->next = sy;
sy = curr;
}
else{
while( temp1->yv < y ){
temp2 = temp1;
if(temp1->next != NULL){
break;
}
temp1 = temp1->next ;
}
if(temp1->next == NULL && y > temp1->yv){
curr->xv = x;
curr->yv = y;
curr->dir = d;
curr->next = NULL;
temp1->next = curr;
} else{
// printf(" %u %u ",temp1,temp2);
curr->xv = x;
curr->yv = y;
curr->dir = d;
curr->next = temp1;
// temp2->next = curr;
}
}
}
}
void main(){
int i ,j ;
struct sorty * curr1 ;
int a[10] = {1,2,3,4,6,5,7,8,9,10};
for( i = 0 ,j =9; i < 10 ; i++,j--){
// scanf("%d",&j);
curr1 = ( struct sorty *) malloc(sizeof(struct sorty));
sort( curr1 ,i,a[j],i);
// printf("asdf\n");
}
curr1 = sy;
while( curr1 != NULL){
printf(" -- %d %d %d \n",curr1->xv,curr1->yv,curr1->dir);
curr1 = curr1->next;
}
curr1 = sy;
while(curr1 != NULL){
curr1 = curr1->next;
free(sy);
sy = curr1;
}
}
|
|
|
|
|
And, what is your question exactly ? (please do not reply with something like "My code doesn't work). Provide some information about the problem you encounter.
And please, read the posting guidelines (first message in this forum).
|
|
|
|
|
mmm... second message of forum (first one is how to answer )Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Yeah but as I programmer, I use 0 based arrays, so this is the message with index 1, thus the first one
|
|
|
|
|
mmm not conviced. Even with 0-based arrays, index 1 would be the second element Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Yeah, I know. I was just finding a silly excuse and did not want to admit that I was wrong
|
|
|
|
|
Having errors is inherent to humans , and (maybe I am wrong but...) AFAIK only CPallini is a klingon, so... no problem.
Have a nice weekend.Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
BTW Arrays are 0 -based, 1 -based thingies are for sissies.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I'm quite sure you program is buggy, anyway you didn't told us what is it supposed to do... If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
In addition to describing your problem, please use code tags and indent your code.
I would suggest that you initialize variables once when you create them, rather than multiple times later on. This would improve your code and eliminate some possibilities for errors.
I would also suggest using the debugger. I've spotted a bug by reading your code, that you should be able to quickly find with the debugger. You have to learn how to do this, best start now.Please do not read this signature.
|
|
|
|
|
Hi all,
I am working on a Win32 application. We are enhancing it by creating some part of UI in .Net/WPF. Our core code is in C/C++ and some part of UI is in .Net/WPF. And We integrate these modules (C/C++ and .Net) via Managed C++.
Now I have to provide drag drop support. I need to drag some content from .Net UI and dropping it in C++/Win32 UI.
Can anybody help me knowing how to go about it?
Or let me know please how to implement drag drop from outside a .Net application (I mean drag from a .Net application and dropping outside it)
If some sample code or hyper-link can is there, please let me know.
Thanks and Regards
Aseem
|
|
|
|