|
john5632 wrote: I have a dll which is having pure virtual functions. Now what to do with that to redifine the function in my own class?
The usual thing you do: derive your class from the abstract one and redefine the methods.
Only the header file of the DLL plays a role in such a game...
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]
|
|
|
|
|
ok, Shell I do load the dll in memory.
Can you please tell the exact steps to do?
|
|
|
|
|
Hello all,
Please tell me how to get window shutdown notification in my MFC application?
-Cvaji
|
|
|
|
|
I know about WM_QUERYENDSESSION
Please tell me whether I can suspend the whole shutdown process when I receives this message
and whether I can resume/cancel the shutdown process.
|
|
|
|
|
I think you cannot suspend the shutdown process, but you can cancel it returning FALSE to the WM_QUERYENDSESSION message.
Maybe, while you are in your WM_QUERYENDSESSION message handler, the shutdown process is suspended, except when ExitWindowsEx was called with the flag EWX_FORCEIFHUNG, but I'm not sure about that.
|
|
|
|
|
Hello Sir
What is the main difference of static variable and Global Variable?
My Suggestion is :
Static variable accessing only through out the class and accessing need for scope resolution operator
Global variable accessing through out the program and accessing the class object.
Sir, My statements are correct or not
Failure is Success If we learn from it!!
|
|
|
|
|
Scoping is possible with a static variable (I'm not talking about a data member of a class, but in general). You could put a static variable within a function and have it retain its value through the life of the program, but the scope is restricted - code from outside the function where it's declared cannot change it.
A static global variable (global scope, but declared as static) is not visible outside the source file where it exists.
You got it right about a static data member.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
Just for the sake of completeness, static is only understood by the compiler to scope the entity.
For the system, it is exactly the same as a global variable.
So if you're using an assembler to write programs, you do not have the luxury of static and you have to do the scoping yourself.
|
|
|
|
|
File = CreateFile(LocalPathPFile, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, \ FILE_FLAG_NO_BUFFERING, NULL);
The handle works perfectly! Except when I try to write I get error 87!
if (!WriteFile(File, Data, (DWORD)BytesReceived, NULL, NULL))
{
wchar_t Error[100];
swprintf(Error, L"Write Error: %d", GetLastError());
Tu(Error);
}
Could this mean because this is in a thread, I have to use overlapped for asynchronous I/O.
I declared an OVERLAPPED *Strc, passed it as 5th argument in WriteFile and still ended up with the same problem!
|
|
|
|
|
Fareed Rizkalla wrote: if (!WriteFile(File, Data, (DWORD)BytesReceived, NULL, NULL))
What type of variables are Data , and BytesReceived , and what are the values of those?
Error 87 means you're passing an invalid parameter (ERROR_INVALID_PARAMETER ), so check what you're passing into the call to WriteFile .
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
Data is char.
BytesReceived is DWORD.
I forgot to remove the DWORD cast, still the same problem exists!
Data is used by a recv TCP/IP function!
|
|
|
|
|
Fareed Rizkalla wrote: Data is char.
Data CANNOT be char . It must be a void pointer. Please read the documentation[^].
Also, learn to use the error lookup utility that comes with VS.
Fareed Rizkalla wrote: BytesReceived is DWORD.
In which case, casting it to DWORD is totally pointless.
Fareed Rizkalla wrote: I forgot to remove the DWORD cast, still the same problem exists!
As I said above.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
So do I have to convert char to LPCVOID?
I got WriteFile once to work with char!
|
|
|
|
|
Huh?
You mean char or char* ?
|
|
|
|
|
And who the hell univoted it?! There, let me fix it.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
Cheers mate!
|
|
|
|
|
File access must be for numbers of bytes that are integer multiples of the volume's sector size.
For example, if the sector size is 512 bytes, an application can request reads
and writes of 512, 1024, or 2048 bytes, but not of 335, 981, or 7171 bytes.
To determine a volume's sector size, call the GetDiskFreeSpace function.
Or try setting the variable Data in WriteFile(File, Data, (DWORD)BytesReceived, NULL, NULL) to be 512, 1024, or 2048 bytes, for debug purposes.
if (!WriteFile(File, 512, (DWORD)BytesReceived, NULL, NULL))
{
wchar_t Error[100];
swprintf(Error, L"Write Error: %d", GetLastError());
Tu(Error);
}
Asynchronous Disk I/O Appears as Synchronous on Windows NT, Windows 2000, and Windows XP
http://support.microsoft.com/kb/156932
Understanding and Using GetDiskFreeSpace and GetDiskFreeSpaceEx
http://support.microsoft.com/kb/231497
|
|
|
|
|
TopCoder23 wrote: File access must be for numbers of bytes that are integer multiples of the volume's sector size.
This is not true, a write can be for any number of bytes; see here[^] for details.
It's time for a new signature.
|
|
|
|
|
He opened the file with FILE_FLAG_NO_BUFFERING. That requires specific alignment and write size restrictions.
So given the following code and assuming 4096 is a correct size, if the write size is set to 16, error 87 will be returned.
void* pBuffer = _aligned_malloc(4096, 4096);
lstrcpyA((LPSTR)pBuffer, "Hello");
DWORD bytesWritten;
HANDLE hFile = CreateFile(L"C:\\Temp\\~tmp.tmp", GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_FLAG_NO_BUFFERING, NULL);
if (!WriteFile(hFile, pBuffer, 4096, &bytesWritten, NULL))
{
printf("Write Error: %u\n", GetLastError());
}
CloseHandle(hFile);
_aligned_free(pBuffer);
|
|
|
|
|
Joe Woodbury wrote: He opened the file with FILE_FLAG_NO_BUFFERING.
Yeah, I missed that; thanks.
It's time for a new signature.
|
|
|
|
|
DWORD DownloadThread(LPVOID lpdwThreadParam)
{
CDownload* Download = (CDownload*)lpdwThreadParam;
WSADATA WS2Info;
if (!WSAStartup(MAKEWORD(2,2), &WS2Info))
{
SOCKET IPv4 = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (IPv4 != INVALID_SOCKET)
{
hostent *ResolveHost;
char *HostName = new char[wcslen(Download->HostName)+1];
wcstombs(HostName, Download->HostName, wcslen(Download->HostName)+1);
HostName[wcslen(Download->HostName)] = '\0';
ResolveHost = gethostbyname(HostName);
if (ResolveHost)
{
SOCKADDR_IN HostService;
HostService.sin_family = AF_INET;
HostService.sin_addr.s_addr=*((unsigned long*)ResolveHost->h_addr);
HostService.sin_port = htons(Download->Port);
if (connect(IPv4, (SOCKADDR*) &HostService, sizeof(HostService)) != SOCKET_ERROR)
{
char *HTTPrequest = new char[DEFAULT_BUFLEN];
char *RequestURI = new char[wcslen(Download->HostFileLocation)+1];
wcstombs(RequestURI, Download->HostFileLocation, wcslen(Download->HostFileLocation)+1);
RequestURI[wcslen(Download->HostFileLocation)] = '\0';
char *Host = new char[wcslen(Download->HostName)+1];
wcstombs(Host, Download->HostName, wcslen(Download->HostName)+1);
Host[wcslen(Download->HostName)] = '\0';
char *UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/5.0.342.9 Safari/533.2";
sprintf(HTTPrequest,"GET %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: %s\r\nAccept: */*\r\nAccept-Encoding:\r\nRange: bytes=%lld-\r\n\r\n",
RequestURI, Host, UserAgent, Download->BytesDownloaded);
send(IPv4,HTTPrequest,strlen(HTTPrequest),0);
delete[] HTTPrequest;
delete[] RequestURI, Host, UserAgent;
char *HTTPresponse = new char[DEFAULT_BUFLEN];
SecureZeroMemory(HTTPresponse, sizeof(HTTPresponse));
recv(IPv4, HTTPresponse, sizeof(HTTPresponse), 0);
********
******** HTTP parsing code
********
int PFDB = 0;
for (int n = 0; n < DEFAULT_BUFLEN; n++)
{
if (HTTPresponse[n] == '\r' && HTTPresponse[n-2] == '\r')
if (HTTPresponse[n-1] == '\n' && HTTPresponse[n+1] == '\n')
PFDB = n+2;
}
DWORD BytesReceived = sizeof(HTTPresponse)-PFDB;
int SPEED = 512;
char *Data = new char[SPEED];
SecureZeroMemory(Data, sizeof(Data));
for (int n1 = 0, n2 = PFDB; n2 < DEFAULT_BUFLEN; n1++, n2++)
Data[n1] = HTTPresponse[n2];
Data[DEFAULT_BUFLEN-PFDB] = '\0';
delete[] HTTPresponse;
int DestinationLength = (wcslen(Download->FileLocation)+wcslen(Download->FileName));
wchar_t *LocalPathPFile = new wchar_t[DestinationLength+1];
wcscpy(LocalPathPFile, Download->FileLocation);
wcscat(LocalPathPFile, Download->FileName);
LocalPathPFile[DestinationLength] = '\0';
HANDLE File;
if (Download->BytesDownloaded == 0)
{
File = CreateFile(LocalPathPFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
FILE_FLAG_NO_BUFFERING, NULL)
if (File == INVALID_HANDLE_VALUE)
Tu(L"File Error!");
}
else
{
File = CreateFile(LocalPathPFile, GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
FILE_FLAG_NO_BUFFERING, NULL);
if (File == INVALID_HANDLE_VALUE)
Tu(L"File Error!");
SetFilePointer(File, 0, NULL, FILE_END);
}
OVERLAPPED *Struc;
do
{
Download->BytesDownloaded += BytesReceived;
TotalBytesDownloaded += BytesReceived;
if (!WriteFile(File, Data, BytesReceived, NULL, NULL))
{
wchar_t Error[100];
swprintf(Error, L"Write Error: %d", GetLastError());
Tu(Error);
}
BytesReceived = recv(IPv4, Data, sizeof(Data), 0);
}
while (Download->DownloadState == Download->ACTIVE
&& Download->BytesDownloaded < Download->BytesToDownload);
delete[] Data;
shutdown(IPv4, SD_BOTH);
CloseHandle(File);
if (Download->BytesToDownload == Download->BytesDownloaded)
{
TotalBytesDownloaded -= Download->BytesToDownload;
TotalBytesToDownload -= Download->BytesToDownload;
Download->DownloadState = Download->FINISHED;
}
else
{
TotalBytesDownloaded -= Download->BytesDownloaded;
TotalBytesToDownload -= Download->BytesToDownload;
Download->DownloadState = Download->PAUSED;
}
}
}
}
else
closesocket(IPv4);
}
WSACleanup();
ExitThread(0);
}
|
|
|
|
|
There are two errors:
First, the fourth parameter of WriteFile must be a pointer to a DWORD (unless you use overlapped IO.)
Second, FILE_FLAG_NO_BUFFERING has strict rules on how the buffers must be aligned. See http://msdn.microsoft.com/en-us/library/cc644950%28v=VS.85%29.aspx[^]. If you violate those rules, one of the errors returned is 87 (for the misaligned data buffer.) If you want to minimize buffering without having to follow the alignment rules, use FILE_FLAG_WRITE_THROUGH. A short discussion of the two can be found at: http://support.microsoft.com/kb/99794[^] (This is a little misleading; the hard drive itself has an onboard cache and this setting has no effect on it.)
|
|
|
|
|
Hi,
I have lots of class and I have a problem. This is,
"An unhandled exception of type 'System.AccessViolationException' occurred in TrafficSim.exe
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
I have classes and their functions.
class FollowAgent
class CreateAgent
{
FollowAgent* dFollowAgent
}
class DriveAgent
{
dCreateAgent = new CreateAgent(...);
...........
dCreateAgent->dFollowAgent= new FollowAgent(...);
}
I think the error is about usage of "dCreateAgent->dFollowAgent". if I use as "dFollowAgent= new FollowAgent(...);" it works normally, but is not my aim.
How can I solve this problem?
Have a good work!
|
|
|
|
|
I think we don't have enough information to really help you. Where does the exception get raised? I mean, what does your program do when it dies? You are (probably) reading from or writing to memory that does not belong to your process, maybe you are using an object that has been freed earlier or using one that hasn't been created yet.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
Hi,
Program running without any error since the line:
dCreateAgent->dFollowAgent= new FollowAgent(...);
I think the problem is about usage of "dCreateAgent->dFollowAgent". I have 3 couples of files.
1. followagent.cpp and followagent.h consist of FollowAgent class.
2. createagent.cpp and createagent.h consist of CreateAgent class.
3. driveagent.cpp and driveagent.h consist of DriveAgent class.
class FollowAgent
class CreateAgent
{
FollowAgent* dFollowAgent
}
class DriveAgent
{
dCreateAgent = new CreateAgent(...);
...........
dCreateAgent->dFollowAgent= new FollowAgent(...);
}
When my program dies, an error window occur. It consist of a message as "An unhandled exception of type 'System.AccessViolationException' occurred in TrafficSim.exe
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
Thanks your reply and I wait another
|
|
|
|
|