|
We try to avoid helping people write virus software. How about using the security built into XP and removing any NTFS permissions to the programs you don't want people using.
|
|
|
|
|
With the extern, can you use your own defined type to share global data or is it limited to int, bool float etc.
i.e.
struct
{
int x, y
float buff[10];
bool onOff;
}myStruct
extern myStruct g_myStruct1;
and how would you init the data.
|
|
|
|
|
1. Yes, but I'm sure you could've figured it out by trying it...
2. Globals are automatically inited to 0. Any other initializtions you may need to do could be accomplised by a special funtion you pass the structure to before you use it.
|
|
|
|
|
I though I understood extern but having second thoughts.
This is because sometimes get linker error if include extern in the global section of the main program.
i.e. they seem to work without using extern in the global section, but only use extern in units where you wish to use them.
e.g.
int g_nMyInt = 2;<br />
bool g_bMyflag = true;
Main()
and then use in the other unit:-
extern int g_nMyInt;<br />
extern bool g_bMyflag;
Wich is correct?
|
|
|
|
|
You only need externs in files where the global variables aren't already defined. Just keep that in mind and you shouldn't have any problems.
|
|
|
|
|
st to re-cap the following are both OK?
extern int g_nMyInt = 3;
extern CMyType g_Mystruct1; // Initialised by a routine at start-up
extern bool g_bMyFlag = true;
Main()
and
int g_nMyInt = 3;
CMyType g_Mystruct1; // Initialised by a routine at start-up
bool g_bMyFlag = true;
Main()
--------------------------------------------------------
and use in other units as required:-
extern int g_nMyInt;
extern CMyType g_Mystruct1; // Initialised by a routine at start-up
extern bool g_bMyFlag;
Many thanks.
Simple questions are sometimes not simple
|
|
|
|
|
You can't initialize an "extern" variable as you are in the first set. Otherwise, those are OK.
__________________________________________
a two cent stamp short of going postal.
|
|
|
|
|
There is no guarantee that any variable, whether global or local, is initialised to 0. In a debug build, using VisualStudio, they do get initialised to 0, but that doesnt apply in a release build.
|
|
|
|
|
Hello
Does anyone know of a way to use AnimateWindow() to fade out a window without blocking at all. If I use the sugested param of 200 ms my application feels unresponsive as the main thread is blocked. The documentation says I cannot call this on a window owned by another thread so I cant spawn off a thread to do it
|
|
|
|
|
I'm experiencing a very weird bug that I can't determine the source of. My only clue are some windows errors which shouldn't be occuring. And I don't just mean I think everything is set up so they shouldn't be occuring, I mean that between when I call SetLastError(0) and GetLastError() I'm not even calling any code that is capable of triggering them. The only explanation I could think of is that my program is somehow corrupting itself, but I've looked through my code carefully and I don't see how. Plus, the VC++ debugger isn't reporting and out of bounds memory access, buffer overuns, or anything else for that matter. I'd like to know if it's possible to set up VC++ to break on a windows error so I can find out excactly where the errors are coming from and why, without having to put a GetLastError() between every line of code.
|
|
|
|
|
Hello all,
I have a question on about how to prevent to prevent the memory leak? I am writing a window program, and I have an Assert() so that if any fatal erorr occured, the Assert() will call
Sleep(INFIITE) to stop the program, and print out the error message to the user. By doing that, the only way to exit the program after Assert() has been called is to close the window. However, it causes a problem which is that even though the desturctor of each classes in the program will be called when the user close the window, there may still some memory leak in the local scoop when I use Assert() like this, eg in funciton f()
f() {
char* name = new char[10];
Assert(AnyError(), "Fatal Error!");
strcpy(name, "Hello");
delete [] name;
}
For example, if I get the Assert() if I get any error in f(), then when the user close the window, I will have a memory leak for 10 bytes. What is the best way to solve the problem? I don't want to use the try and catch block since the code will be mess up with all those try and catch block. And I really want to stop the program when the fatal error occurs. Any ideas? Thanks!
Nacho
|
|
|
|
|
Im not sure i fully understand.
If you program has hit a fatal error and is exiting then you could probably not worry and rely on the OS to clean up after you.
Perhaps you could use a smart pointer
A smart pointer is usually a template class that pretends to be a pointer by providing the -> and * operators.
Because the smart pointer itself is on the stack its destructor will be called and you can delete the memory then.
I think the stl has a smart ptr template. You might want to start there
However if your Assert() function never returns then that wont work either.
Why dont you throw an exception in your Assert() function and catch it at a higher level
Good luck
|
|
|
|
|
Thanks for your suggestion. I know the way the smart pointer works, but as what you said, since the Assert function never return, smart pointer is no use in this case. Also, if I throw an exception, then, the try and catch block will go around in my code. That is so messy then! But thanks for your comment!!
|
|
|
|
|
As you are trying to deal with a rather general error could you not catch the exception once at a higher level? In your main() for example. If you are writing an MFC app im sure you could override CWinApp::Run() and put your try..catch in there.
|
|
|
|
|
if you run on something else than Win 3.11
the OS cleans up after you...
|
|
|
|
|
Thanks! But do you know how the OS clean is up for me? You mean the OS will keep doing a background search for the memory leak? Am I right? Thanks!
|
|
|
|
|
the OS has a table with all the memory you alocated,
and when your program exits , the OS throws away
that table and the Memory is free for other programs...
|
|
|
|
|
Hi,
I am in the development of implementing the read/write operation in the WIN CE environment through COM Port
I used the following code ...
//==============================================================
gCommHandle = CreateFile(L"COM1:",
GENERIC_READ|GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
bWrite = WriteFile(gCommHandle, "Test Msg", 8, &dwWrite, NULL);
//==============================================================
I could able to get the gCommHandle and the Writefile function also return TRUE after execution
But nothing is getting written in the COM Port...(I observed this by the serial port monitoring tool)
How can we perform read/write operation in COM port in WIN CE OS. Can some one help me in this regard.
Thanks in advance,
~Chinna
Hard Work Never Fails
|
|
|
|
|
Hi all,
I'm trying to do the following :
std::queue <MyManagedClass *> m_qSomeName;
but I get the following compile error
...\Vc7\include\deque(59): error C2847: cannot apply sizeof to managed type 'TestApp1::MyManagedClass'
ok.. so I changed MyManagedClass to a non Managed Class, and now I get a different compile error:
...\TestApp1\MyServer.h(29): error C3633: cannot define 'm_qSomeName' as a member of managed 'TestApp1::MyServer'
Now I'm just trying things out, but is it not possible to use the std::queue template class in managed c++? what about other STL classes?
<EDIT>
Before anyone says, why aren't you using .NET queue/list classes. I'm geniunely curious why I am not able to use STL
</EDIT>
Thanx
|
|
|
|
|
|
outstanding!! thanx very much Nemanja.
Reading through your article and its great.
giving it a big 5.. too bad there isn't a 6
If there's one thing I've learned, it's that life is one crushing defeat after another until you just wish Flanders was dead. - Homer Simpson
|
|
|
|
|
Dear All,
I have a query on following case.Can some body tell the solution for the following:
y = 5++++6*3;
The answer turns out to be -12 when checked with a C compiler
Also, i tried the same on borland delphi 5 and got the answer as 24
How is the processing going on in the above case.
Thanks,
Regards,
Rohit
|
|
|
|
|
Rohit Divas wrote:
y = 5++++6*3;
I would think code that would not even compile. No wonder it is giving you indeterminate results.
"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!
|
|
|
|
|
|
I tried to compile that in some code, and didn't succeed at all.
it didn't like the ++ after the 5. I believe it expects a variable. so i'm not sure how you got that to compile
why are you doing ++++ anyway?
|
|
|
|