|
I am using GD+ in my ActiveX Control. It Works. But TSTCON32.exe not removed from memory.It is still running even after i closed testContainer(TSTCON32) application. Please look at this simple code and tell me problem.
Here is the Code.It simply initialize in InitInstance and Shutdowns in ExitInstance.
AfxStd.h
/////
#if !defined(AFX_STDAFX_H__C2F7B03D_540F_42F2_B794_2FEF9ED71973__INCLUDED_)
#define AFX_STDAFX_H__C2F7B03D_540F_42F2_B794_2FEF9ED71973__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently,
// but are changed infrequently
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#include <afxctl.h> // MFC support for ActiveX Controls
#include <afxext.h> // MFC extensions
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Comon Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment(lib, "gdiplus.lib")
// Delete the two includes below if you do not wish to use the MFC
// database classes
#include <afxdb.h> // MFC database classes
#include <afxdao.h> // MFC DAO database classes
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__C2F7B03D_540F_42F2
TestApp.H - Application class header file.
#if !defined(AFX_DFDSF_H__B2B70A2B_F958_46E4_B51D_CE3FE9A11D59__INCLUDED_)
#define AFX_DFDSF_H__B2B70A2B_F958_46E4_B51D_CE3FE9A11D59__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// dfdsf.h : main header file for DFDSF.DLL
#if !defined( __AFXCTL_H__ )
#error include 'afxctl.h' before including this file
#endif
#include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// CDfdsfApp : See dfdsf.cpp for implementation.
class CDfdsfApp : public COleControlModule
{
private:
GdiplusStartupInput gdiplusStartupInput; // GDI+ Object
ULONG_PTR gdiplusToken; // GDI+ Pointer
public:
BOOL InitInstance();
int ExitInstance();
};
extern const GUID CDECL _tlid;
extern const WORD _wVerMajor;
extern const WORD _wVerMinor;
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_DFDSF_H__B2B70A2B_F958_46E4_B51D_CE3FE9A11D59__INCLUDED)
////////////////////////////
TestApp.Cpp - Applications cpp file
#if !defined(AFX_DFDSF_H__B2B70A2B_F958_46E4_B51D_CE3FE9A11D59__INCLUDED_)
#define AFX_DFDSF_H__B2B70A2B_F958_46E4_B51D_CE3FE9A11D59__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// dfdsf.h : main header file for DFDSF.DLL
#if !defined( __AFXCTL_H__ )
#error include 'afxctl.h' before including this file
#endif
#include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// CDfdsfApp : See dfdsf.cpp for implementation.
class CDfdsfApp : public COleControlModule
{
private:
GdiplusStartupInput gdiplusStartupInput; // GDI+ Object
ULONG_PTR gdiplusToken; // GDI+ Pointer
public:
BOOL InitInstance();
int ExitInstance();
};
extern const GUID CDECL _tlid;
extern const WORD _wVerMajor;
extern const WORD _wVerMinor;
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_DFDSF_H__B2B70A2B_F958_46E4_B51D_CE3FE9A11D59__INCLUDED)
These are only files which has code related to GDI+. I used ActiveControl Wizard. And I added the code to StartUp GDI+ nad Shutdown GDI+. That's it. I did not write any other code.
|
|
|
|
|
im now doing digit recognition,but cant run at all,problems is exist..
i cant solve for the header file too,even look through example in textbook,hv same problem..
i understand the counting of MLP,but when apply into my coding,hv problem..how???
thanks for reply..
|
|
|
|
|
hi all,
suppose that I have a File Called "abc.mdf" in C Drive ..Now I want to copy it to another directry in "D" Drive ..
So How do I do it using C++?
Thanks in advance..
|
|
|
|
|
You can call Win32 API
CopyFile(
"C:\\abc.mdf", // name of an existing file
"D:\\abc.mdf", // name of new file
FALSE // operation if file exists
);
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
CopyFile() or SHFileOperation() .
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Is it possible to use XP's built-in text-to-speech functionality in a C++ or C# application, without requiring the user to install any speech redistributable?
|
|
|
|
|
Dear All
Who had worked with 3D Studio Max or programmed in OpenGL please helped me !
I want to create a program that can control an character to animate according to user's action. For example if user press key 'A' then the character kick, if press 'B' then character punch,etc. My idea is reading key frame chunks in 3DS file that contains the info about characte animation(.3ds) and process to animate character, but how can I do this ? I don't know.
I am using 3D Studio Max 7 and I don't know the format of 3DS file that export from 3D Studio Max 7, so if you know please help me.
If you know any source code of reading 3DS file (.3ds) and process to animate character in this 3ds file by OpenGL,please tell me .
Thanks a lot.
|
|
|
|
|
Doesn't the 3D Studio Max SDK include support for 3DS files?
|
|
|
|
|
Dear you
I just know that, 3D Studio Max can export it's '.max' file to .3ds file format. For example, if i have a file named 'myleg.max', this file ('myleg.max') contains the model of my leg ( include mesh info,material info,etc). 3D Studio Max can export 'myleg.max' to 'myleg.3ds' and now my program must read 'myleg.3ds' by C++,OpenGL for simulate my leg and animate my leg. Ofcourse, in 3D Studio Max, I have been animated 'myleg.max' so in 3D Studio Max IDE, I can play an animation about my leg based on 'myleg.max'.
But at the moment I don't know how to read 3DS file (.3ds) and create animation based on this file by VC++,OpenGL
Thanks and regards
|
|
|
|
|
There are several "interlocked" functions such as InterlockedIncrement. All these functions change the interlocked variable value. There is no "get" function to just look at the value. Does this mean that threads can use the variable with normal references as long as they do not change it?
The value of the variable could be learned using InterlockedExchangeAdd of zero, or InterlockedCompareExchange with the same comparand as the exchange value. These obviously have more overhead than simple access.
-Obi Wan 2
|
|
|
|
|
From MSDN:
Simple reads and writes to properly-aligned 32-bit variables are atomic.
...
The interlocked functions should be used to perform complex operations in an atomic manner.
So only the ops that would require more than one step to mod the value have an interlocked function.
Also (from MSDN),
Simple reads and writes to properly aligned 64-bit variables are atomic on 64-bit Windows. Reads and writes to 64-bit values are not guaranteed to be atomic on 32-bit Windows. Reads and writes to variables of other sizes are not guaranteed to be atomic on any platform.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
I had read this, but in my view it is not completely clear.
cmk wrote:
From MSDN:
Simple reads and writes to properly-aligned 32-bit variables are atomic.
This suggests that one could set the value of a variable by normal means. If that was the case, why is there an "InterlockedExchange"? Of course that answer is that it changes two variables atomically.
Thanks for your answer. I am proceeding based on this being the fact. I was looking for some confirmation. I am sure you are aware that finding problems with interlocking in a complex application with many threads accessing common data is daunting.
-Obi Wan 2
|
|
|
|
|
InterlockedExchange(&v, 0) creates a memory barrier.
It forces any cached memory changes for a processor to be flushed to main memory and made visible to other processors.
For the same reason you may want to do an InterlockedExchangeAdd(&v, 0) to get the value of v, that is to create a memory barrier.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
This seems to question what "Simple reads and writes to properly-aligned 32-bit variables are atomic" means, my original question. I think you are saying that if a thread wants a variable's value a simple read may NOT get the current value unless the interlocked functions are used. For example, when processor-A caches a variable's value and then processor-B changes the value using an interlocked function before processor-A actually uses the value, processor-A will use the unchanged value. If this is the case, simple reads and write can only work when you have a priori knowledge that no other thread is changing the value.
I was hoping to avoid using "InterlockedExchangeAdd(&v, 0)" to get the value of the interlocked variable for performance reasons, but this seems risky.
-Obi Wan 2
|
|
|
|
|
Obi Wan 2 wrote:
I was hoping to avoid using "InterlockedExchangeAdd(&v, 0)" to get the value of the interlocked variable for performance reasons, but this seems risky.
By using it you will be sure that if another processor/thread has just changed the value that you are getting the new value, not an old cached value. Making the variable volatile _may_ be good enough (more below).
I find it all a little vague in spots as well.
Here's my take on things based on either intel manuals, msdn, ARM, ...:
"Simple reads and writes to properly-aligned 32-bit variables are atomic"
To me, this means (as they also mention), that if one thread is reading a 32-bit value at the same time another is writing to it you won't read a partially written value (i.e. all bytes will be set at once). However, it is unclear to me how this translates to a multi-processor situation where one processor/thread writes to the 32-bit value, and the write is cached, and another processor/thread then tries to read the value. I expect that the second p/t could read an old value from it's cache, or from main memory as the new value is still in the first p/t cache.
A lot of people use volatile to prevent the system from caching values, they use it as if it garanteed atomic behaviour because of this.
The ARM says "there are no implementation-independent semantics for volatile objects; volatile is a hint to the compiler to avoid agressive optimization ..."
From MSDN:
"The system always reads the current value of a volatile object at the point it is requested, even if the previous instruction asked for a value from the same object. Also, the value of the object is written immediately on assignment. One use of the volatile qualifier is to provide access to memory locations used by asynchronous processes such as interrupt handlers."
To me, this implies they create a barrier on read/write access of a volatile - which is likely why people treat it as if it does.
Because the language does not define this as expected behaviour, in my opinion, the only way to write portable/future safe code is to use the interlocked functions. These use the intel asm lock instruction to create a barrier.
The barrier not only flushes the specified variable to main memory, it also fushes any other cached writes for any other variables.
For me the following from MSDN is one of the clearer examples on the use of the interlocked functions:
When a processor writes to a memory location, the value is cached to improve performance. Similarly, the processor attempts to satisfy read requests from the cache to improve performance. Furthermore, processors begin to fetch values from memory before they are requested by the application. This can happen as part of speculative execution or due to cache line issues.<br />
<br />
As a result, multiple processors can have different views of the system memory state because their caches are out of synch. For example, the following code is not safe on a multiprocessor system:<br />
int iValue;
BOOL fValueHasBeenComputed = FALSE;
extern int ComputeValue();
void CacheComputedValue()
{
if (!fValueHasBeenComputed)
{
iValue = ComputeValue();
fValueHasBeenComputed = TRUE;
}
}
BOOL FetchComputedValue(int *piResult)
{
if (fValueHasBeenComputed)
{
*piResult = iValue;
return TRUE;
}
else
return FALSE;
}
There is a race condition in this code on multiprocessor systems because the processor that executes CacheComputedValue the first time may write fValueHasBeenComputed to main memory before writing iValue to main memory. Consequently, a second processor executing FetchComputedValue at the same time reads fValueHasBeenComputed as TRUE, because the new value of iValue is still in the first processor's cache.<br />
<br />
Processors can be instructed to force their memory caches to agree with main memory with special instructions. Such instructions ensure that previous read and write requests have completed and are made visible to other processors, and to ensure that that no subsequent read or write requests have started. Examples are:<br />
<br />
Functions which enter or leave critical sections. <br />
Functions which signal synchronization objects. <br />
Wait functions. <br />
Interlocked functions <br />
Consequently, the multiprocessor race condition above can be repaired as follows:
void CacheComputedValue()
{
if (!fValueHasBeenComputed) {
iValue = ComputeValue();
InterlockedExchange((LONG*)&fValueHasBeenComputed, TRUE);
}
}
The InterlockedExchange function ensures that the value of iValue is updated for all processors before the value of fValueHasBeenComputed is set to TRUE.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
I take volitile to mean the same as you describe. It instructs the compiler to make no assumptions about the value of the variable within the code unit. Otherwise, the compiler might not get a fresh copy from memory when it knew that code unit had not changed it. How this carries over to multi-processors and caching is not clear, but I suspect it provides no benefit as the compiler would be unaware of caching and multi-processors. The fresh copy it gets could easily come from that processor's cache...different than the value in some other processor's cache or memory.
While the issue still remains foggy to me, this discussion has been helpful. Thanks.
-Obi Wan 2
|
|
|
|
|
A while ago I started this thread, trying to better understand how the Interlocked... functions work. Since that time I have tried many, many different approaches on single-processors, single-processors w/HyperThreading, multi-processors and multi-processors w/HyperThreading...all 32-bit. At times I doubted the integrity of these instructions, but in every case I found a subtle programming error of mine that restored my faith. They all work EXACTLY as advertised.
In the original posting, I questioned why there is no "InterlockedGet," speculating that an InterlockedExchangeAdd of zero could be used. The real reason that there is no "InterlockedGet" is because it is unnecessary (for aligned 32/64-bit variables on a 32/64-bit processor). Aligned 32/64-bit reads are atomic.
One subtlety that trapped me was that the variables (in some cases at least) must be declared volatile if you want to be guaranteed the "current" value is used everywhere within the translation unit.
The issue that Interlocked... function addresses is memory that is alreasy in the processor(s) cache, doing a bus lock that forces all caches to get refreshed wven that value is updated. This is distinct from a value that the compiler optimization might hold in a register, which is addressed by volatile.
At this point I have NO questions, but thought my results might be helpful to others.
-Obi Wan 2
|
|
|
|
|
Are there any memory limitations on a process short of the actual available memory? If so, what are they? Are they operating system dependent...Windows XP vice Windows Server 2003?
-Obi Wan 2
|
|
|
|
|
The theoretical limit is 2GB per process.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Thanks...this is consistent with my observations.
-Obi Wan 2
|
|
|
|
|
Hello,
I have a problem in my C program code. I want to restart or recreate a process which was suspended and its state was saved in a binary file and then terminated. Now i want to recreate/restart it using its previous state.
I tried to use the functions below but it seems the functions do not work.
Help me please, part of my code:
<br />
case 6:
lpBaseAddress = 0;<br />
hProcess = mbi.BaseAddress;<br />
SetThreadContext( <br />
hThread, <br />
lpContext <br />
);<br />
WriteProcessMemory(<br />
hProcess,
lpBuffer,
nSize,
lpNumberOfBytesWritten
);<br />
ResumeThread(pi.hThread);
GetLastError();<br />
break;<br />
what am i missing here, or i have to call the createprocess() function again?
oam
|
|
|
|
|
See you said you terminated the process. Then how can you resume it ?
Only Suspended process can Resumed. Not Terminated Process.
You should not terminate it.Just Suspend it.
|
|
|
|
|
In process migration, there should be a way of restarting a suspended process(check pointed process) in the other machine on the network. Ifact i want to used the saved process information like baseaddress, context e.t.c after it was suspended. So there should be a possible way. But the big question how????
oam
|
|
|
|
|
I wrote some MSDOS programs in C++ many years ago (Borland's C++) and so I'm not very knowledgeable about the current Visual C++, but here is what I want to do and it doesn't seem like it should be too difficult.
I have a web site that displays a table of records and each line has a microphone icon on it. When the user clicks on that mic icon another web page is opened and it tells the user they may create a dictation. (We have special dictation mics running from a vb.net app that runs from the user's local machine.) We also have an image display program running at the same time and it also runs from the user's machine.
The web app knows what the StudyID is but the vb.net apps don't and I need to be able to pass that StudyID to the local machine so it can be used by the image display program to find the correct images to display while the user is dictating.
I wrote a "faux" activeX (dll) in vb.net that could be placed on the web site and run when the 2nd page is displayed and the studyID could be passed to it and then it would use the study ID and the Process class to cause the image display program to display the correct images, but that would require each user's machine to have the correct security manually setup in .Net Configuration and we don't want to have to do that. So I thought maybe an ActiveX written in C++ could basically do the same thing.
Does this make sense? Could this be done and if so, would it be as easily done as I think it might be.
|
|
|
|
|
I'm having trouble figuring out what to do with this program...any help would be greatly appreciated
Cheers!
Write a program that prompts for a file name and then reads the file to
check for balanced curly braces, {}; parentheses, (); and square brackets,
[]. Use a stack to store the most recent unmatched left symbol. The program
should ignore character that is not a parenthesis, curly brace, or square
bracket. Note that proper nesting is required. For instance, [a(b]c) is
invalid.
Sample runs:
Output
1. {{a+5}-7*[1-{4/2}]}/{2*(3-6)} Valid
2. {(a+5)-7*[1-{4/2}])/{2*(3-6)} Invalid
|
|
|
|
|