|
|
nguyenvhn wrote:
const int a=10;
This simply means that you cannot modify memory address 0x0012FF7C through variable a . The address is not read-only, the variable is. make sense?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
teu teu teu, read the other posts before saying so, especially "Christopher Lloyd"'s one
TOXCCT >>> GEII power
|
|
|
|
|
In which case he states that "it just tells the compiler that you shouldn't be able to change a using a line like a = 20" In my post, I stated that "you cannot modify memory address 0x0012FF7C through variable a"
What's your point?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
yes you can
const is only a specification for the compiler!!!
if you had read all the posts here, you would have seen that we already said that also... and i even that i was thinking like you !
TOXCCT >>> GEII power
|
|
|
|
|
Then how would you propose changing the value through variable a ?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
by a pointer to its address. int* p = &a; . this works, but badly, the compiler replaced each occurence of a by its value (10 here).
that is why, even if the value contained at the adress of a is changed, the compiler used each a uses as a #define . int d = a; will affect 10 to d, even if the line before was *p = 100; .
Do we now understand better ?
TOXCCT >>> GEII power
|
|
|
|
|
int *p = &a;
*p = 100; This does not change the value through variable a . The value is changed through variable p . Do you still find my original "...you cannot modify memory address 0x0012FF7C through variable a. The address is not read-only, the variable is" statement to be false.
I *think* we are saying the same thing, so I'm not quite sure why this thread is six posts longer than necessary.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
#include <iostream>
using namespace std;
int main(){
int a=10;
int* p=(int*)&a;
*p=100;
int i=a;
cout << "p=" << p << endl;
cout << "&a=" << &a << endl;
cout << "*p=" << *p << endl;
cout << "a=" << a << endl;
cout << "i=" << i << endl;
return 0;
}
the running result
p=0012FF7C
&a=0012FF7C
*p=100
a=100
i=100
|
|
|
|
|
why are you tampering code by removing const while declaring variable a.
it should be const int a=10;
The chosen One
|
|
|
|
|
this is because of compiler optimization. Just have a look at assembly code.
const int a=10;
0041B1CE mov dword ptr [a],0Ah
int* p=(int*)&a;
0041B1D5 lea eax,[a]
0041B1D8 mov dword ptr [p],eax
*p=100;
0041B1DB mov eax,dword ptr [p]
0041B1DE mov dword ptr [eax],64h
int i=a;
0041B1E4 mov dword ptr [i],0Ah
Also while printing on console...
cout << "a=" << a << endl;
0041B291 push offset std::endl (4194BAh)
0041B296 push 0Ah
0041B298 push offset string "a=" (44E0C8h)
0041B29D push offset std::cout (457668h)
0041B2A2 call std::operator<<<std::char_traits<char> > (419A96h)
0041B2A7 add esp,8
0041B2AA mov ecx,eax
0041B2AC call std::basic_ostream<char,std::char_traits<char> >::operator<< (4195DCh)
0041B2B1 mov ecx,eax
0041B2B3 call std::basic_ostream<char,std::char_traits<char> >::operator<< (419AC3h)
You will not experience this behavour with all the compilers.
Thanks,
Anand
The chosen One
|
|
|
|
|
When I try to load any DLL with LoadLibraryEx, it gives a NULL-handle and the last error (GetLastError) is ERROR_SHARING_VOILATION. I'm using LoadLibraryEx, because I want to load a DLL that I found using CFileFind (or however it's called).
Does someone know how to solve that? Even looping (+::Sleep(50)) until the last error is not ERROR_SHARING_VIOLATION won't help (it will hang the application).
|
|
|
|
|
Are you sure that GetLastError() is returning the correct code? Before calling LoadLibraryEx() , do a SetLastError(0); to make sure.
Also, check which other app has loaded the DLL.
Bikram
|
|
|
|
|
Another perfect example of my stupid moves:
First I load the DLL with the CFile object, and then with LoadLibraryEx. What did I do wrong? I forgot to tell CFile to CFile::shareDenyNone.
Tnx.
|
|
|
|
|
HI..
I want to use DirectShow to capture viceo from tv tunner card and want to save it on disk in compressed format. which format is more compressed .. AVI is ahviear on disk
Can i do it ,, how if yes...
wt is difference between this and simple capturing using USB cam..
reply
also code if any abut tv tunner capturing
thanx
|
|
|
|
|
Take a look in the AmCap Sample in the DXSDK
DirectX 9.0 SDK
It is a good example, but you need have some notion on DirectShow.
[]'s
Marcos Vinícius
|
|
|
|
|
Hi All,
Ive created a bare Win32 DLL. Ive exported a function and can get the functions address with no problems in my calling application.
My problem is after the DLL function is called I get the message "The value of ESP was not properly saved across a function call".
My code is...
DLL HEADER
---------------
#ifdef JDEDXMLPARSER_EXPORTS
#define JDEDXMLPARSER_API __declspec(dllexport)
#else
#define JDEDXMLPARSER_API __declspec(dllimport)
#endif
// This class is exported from the jdedXMLParser.dll
class JDEDXMLPARSER_API CJdedXMLParser {
public:
CJdedXMLParser(void);
dllAddFile(TCHAR* szFile);
// TODO: add your methods here.
};
// This integer is exported
extern JDEDXMLPARSER_API int nJdedXMLParser;
// This function is exported
JDEDXMLPARSER_API AddFile(TCHAR * sz);
DLL CPP
----------
JDEDXMLPARSER_API AddFile(TCHAR *sz)
{
MessageBox(NULL, sz, L"", 0);
//parser.dllAddFile(szFile);
}
CALLING THE DLL
----------------------
// Globals
typedef (WINAPI* AddFile)(TCHAR *sz);
AddFile _AddFile;
void CUnicodeTestDlg::OnBegin()
{
HMODULE m_lib;
TCHAR * szTable = _T("F0101");
m_lib = LoadLibrary(_T("jdedXMLParser.dll"));
_AddFile = (AddFile) GetProcAddress(m_lib, "?AddFile@@YAHPAG@Z");
_AddFile(szTable);
}
When I call _AddFile I get MY message box from the DLL function followed by the system error ESP message. Does anyone know what I am doing wrong here?
I dont have a .def file as im not sure how to link it in and use it so I am using the FULL function name.
Thanks in advance for any help.
Kind Regards,
Chris
|
|
|
|
|
Hi Chris,
I just had the same problem with the ESP error. In my case it was because the exported DLL function had the __stdcall calling convention as part of the function prototype. I wasn't including that in my typedef for the function pointer.
I noticed you export the function with no calling convention, but then include the WINAPI convention in your typedef. Have you tried removing WINAPI from your typedef? See if that works.
Regards,
Justin
|
|
|
|
|
You're right. This happens in VC++ due to a mismatch in the calling function convention. Make sure you are using the correct convention: __stdcall / __cdecl etc.
Bikram
|
|
|
|
|
Does anybody know the class name, part id's and state id's for static controls? MSDN lists details for just about every other control but not statics.
Systems AXIS Ltd - Software for Business ...
|
|
|
|
|
I've been trying to read about the best network I/O model and talked to people about which network I/O model is the best. Different answers from different peopels about the same model.
Asynchronous I/O: One says it's the best model for concurrent operations, an other says it's bad because of a lot of synchronizing/locking when access shared data (such as client list on a server), then a third says, locking is not bad...man, this is kinda confusing.
Synchronous I/O - using select(): I would say this one is bad, because then you have to wait for each operation to copmplete before you can move on. Other people says this is a great network I/O model.
What is your opinion about the best network I/O model?
Rickard Andersson
Here is my card, contact me later!
UIN: 50302279
Sonork: 37318
|
|
|
|
|
Asynchronous is very difficult to program. You really have to split up your operations into various states to process as different bits of I/O complete. Typically you'd use asynchronous I/Os to get the best out of a thread-pooled server - you can have more I/O pending than you have threads, and you can perform part of a second client's request while waiting for I/O for the first to complete.
For best performance, you want to have a limited-size pool of threads, rather than one thread per client, for several reasons. Firstly there's overhead in creating and cleaning up threads. Secondly, each thread requires its own stack and possibly its own thread-local resources, which use up memory that you could be using for other things. Thirdly, the more threads there are which can run at any given time, the more time the OS spends switching between threads and the less actually doing work. The ideal is to have only one runnable thread per CPU. SQL Server uses this model (see Inside the User Mode Scheduler[^]).
Writing your code this way can give you the maximum potential performance, but it's hard.
Synchronous I/O is much easier: you simply write the code to perform the required steps in the required order. But you typically need more threads to achieve the same goal; if a thread is blocked waiting for I/O to serve one client, it can't serve another.
Synchronisation is an issue whether you're using asynchronous or synchronous I/O, so long as you're using multiple threads that may access the same shared data. It's a fact of life in a multithreaded program. It doesn't affect your choice of sync or async I/O. Locking reduces your concurrency, sure, if two threads contend on the same shared data. You can potentially improve this by increasing the granularity of your locks - locking less data, and holding locks for less time.
Windows provides the I/O completion port facility for simplifying and improving thread pooling. Threads and I/O handles can be associated with a particular completion port. Handles are associated by calling CreateIoCompletionPort ; threads call GetQueuedCompletionStatus to block waiting for an I/O (on any of the handles associated with the port) to complete. So far, so simple. The twist is that the completion port enforces the maximum concurrency level - it will only unblock threads up to a specified number of threads running concurrently. What's more, if a thread belonging to the port is blocked for any reason, the completion port will release another if a completed I/O is waiting to be processed. This does mean that the number of runnable threads will typically be higher than the ideal one-per-processor.
Finally, to improve processor cache locality, the port releases threads in Last-In-First-Out order - the thread that handles a completed I/O is the last one which called GetQueuedCompletionStatus . These facilities have been present since NT 3.5. They're quite complex, however, for general thread pooling. For that, Windows 2000 also offers the QueueUserWorkItem API.
I suggest reading Programming Server-Side Applications for Windows[^] by Jeffrey Richter.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
When I click on a button I want to appear 3 buttons instead a dialog.How can I do this?Thanks.
|
|
|
|
|
One way is you create 3 that buttons in resource editor. In OnInitDialog, you set three button to be invisible.
When click on a button, you set 3 button to visible mode.
Just call: ShowWindow
Another way is to create buttons when click by CWnd::Create function
|
|
|
|
|
Idon't want a dialog, only 3 buutons.No dialog.
|
|
|
|