|
This would explain what is happening, could you explain in a little more detail please?
Elaine
The tigress is here
|
|
|
|
|
I guess InvalidateRect posts the wm_paint message and the message is pumped by the mfc framework.
-prakash
|
|
|
|
|
Just curious, but what is being drawn in OnPaint()?
The problem is I see you creating a compaltible bitmap, but I do not see you selecting that bitmap into m_MemDC (before drawing to m_MemDC). If that is the case, then you are not drawing on the compatible bitmap. You would be drawing on the default bitmap which is monochrome, supporting black and white only.
INTP
Every thing is relative...
|
|
|
|
|
hello everyone,
i have a simple inheritence question for anybody knows...
let's take an example. I have the following class definition :
class CVCalcParserException {
protected:
int m_iExceptionNumber;
std::string m_strExceptionMsg;
int m_iErrorPos;
public:
CVCalcParserException(int iExceptionNumber,
const std::string& strExceptionMsg,
int iErrorPos);
virtual ~CVCalcParserException();
int GetExceptionNumber();
std::string GetMessage();
int GetErrorPos();
};
In the current state of my class, people could be able to create an instance of it, but I'd like to forbbid this as CVCalcParserException .is supposed to provide some services to the derived classes.
How could i set this class abstract ? the getter functions are not to be overloaded so i cannot put them as pure virtual functions (using =0).
any idea ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Declare the constructor as protected.
class CVCalcParserException {
...
protected:
CVCalcParserException(int iExceptionNumber,
const std::string& strExceptionMsg,
int iErrorPos);
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
S. Senthil Kumar wrote: Declare the constructor as protected
hum, yeah, i thought to this, but wasn't sure...
thank you
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
tell me one more thing, i explicitely define only one constructor with parameters, so, the compiler implicitely defines a default constructor without parameters.
should i also explicitely define this constructor protected ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
toxcct wrote: i explicitely define only one constructor with parameters, so, the compiler implicitely defines a default constructor without parameters.
It doesn't. Explicitly defining a constructor suppresses generation of the compiler generated one, so no, you don't need to define the parameterless constructor.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
|
How about making the constructor protected.
If you do that it will be accessed only in derived class.
Note: I never tried to do so. Why do you try and let me know too.
Regards
|
|
|
|
|
Let me confess that I am fresher in network programming can any one help me???
I made very simple server using IOCP but my server is unable to receive all the message. Here is code for my server
#include "stdafx.h"
//#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include "winsock2.h"
#include "fstream"
#include "conio.h"
#include "stdio.h"
#pragma comment(lib,"ws2_32.lib")
/*--- MACRO Defination --*/
#define SERVER_PORT htons(8888)
#define DATA_BUFSIZE 4096
#define OP_READ 0
#define OP_WRITE 1
#define OP_ACCEPT 2
/* OverlapPlus Data Used to store Ovelap info and other information need to user*/
typedef struct _OVERLAPPEDPLUS
{
OVERLAPPED Overlapped;
SOCKET sServer,sClient;
int nOperationCode;
WSABUF wbuf;
DWORD dwBytes,dwFlags;
SOCKADDR_STORAGE ClientAddr;
int nClientNumber;
}OVERLAPPEDPLUS, * LP_OVERLAP_PLUS;
void Initialize();
DWORD WINAPI ServerWorkerThread(LPVOID lpParam);
FILE *stream;
void appendLog(TCHAR* strMessage)
{
stream = _wfopen( _T("c:\\iServer.log"), _T("a") );
fputws(_T("\n"),stream);
fputws(strMessage,stream);
fclose( stream );
}
int main()
{
WSADATA wsd;
SYSTEM_INFO SystemInfo;
SOCKADDR_IN InternetAddr;
SOCKET sListen;
HANDLE hIocp;
int nClientInc = 1;
/* Initialize Winsock2 */
Initialize();
/*--- Create an I/O completion port ---*/
hIocp = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, (ULONG_PTR)0, 0);
if(NULL == hIocp)
{
printf("Error in initialization of Completion Port! Press any to exit...");
return -1;
}
/* Determine how many processors are on the system, For thead optimization */
GetSystemInfo(&SystemInfo);
/*--- Create worker threads based on the number of processors available on the system ---*/
for(int nProcessor = 0; nProcessor < (int) SystemInfo.dwNumberOfProcessors; nProcessor++)
{
HANDLE ThreadHandle;
ThreadHandle = CreateThread(NULL, 0,ServerWorkerThread, hIocp,0, NULL);
//CloseHandle(ThreadHandle); // Why We close thread Handle ?????
}
/*--- Create a listening socket --- */
sListen = WSASocket(AF_INET, SOCK_STREAM, 0, NULL, 0,WSA_FLAG_OVERLAPPED);
/*--- Fill TCP Header Info for bind a socket ---*/
InternetAddr.sin_family = AF_INET;
InternetAddr.sin_addr.s_addr = htonl(INADDR_ANY);
InternetAddr.sin_port = SERVER_PORT;
/*-- Bind the socket with port --*/
bind(sListen, (PSOCKADDR) &InternetAddr, sizeof(InternetAddr));
/*--- Prepare socket for listening mode and Start the Server ---*/
listen(sListen, 5);
printf("Server Started in listen mode ....");
while(TRUE)
{
int ret;
char strBuffer[DATA_BUFSIZE];
ULONG_PTR *PerHandleKey;
OVERLAPPED *Overlap;
OVERLAPPEDPLUS *OverlapPlus,*olpClientOverlappedPlusData;
DWORD dwBytesXfered;
SOCKET sClient;
SOCKADDR_IN saRemote;
int nRemoteLen;
/*-- Accept connections and assign to the completion port--*/
nRemoteLen = sizeof(saRemote);
sClient = WSAAccept(sListen, (SOCKADDR *)&saRemote,&nRemoteLen,0 , 0);
printf("New Client! Socket number %d connected\n", sClient);
/* Allocate memory to olpClientOverlappedPlusData */
olpClientOverlappedPlusData = (LP_OVERLAP_PLUS)GlobalAlloc(GPTR, sizeof(OVERLAPPEDPLUS));
if(NULL == olpClientOverlappedPlusData)
{
printf("Error in initialization Memory! Press any to exit...");
return -1;
}
/*-- Fill OverlapPlusData -- */
olpClientOverlappedPlusData->sClient = sClient;
olpClientOverlappedPlusData->nClientNumber = nClientInc++;
olpClientOverlappedPlusData->nOperationCode = OP_READ;
olpClientOverlappedPlusData->wbuf.buf = strBuffer;
olpClientOverlappedPlusData->wbuf.len = DATA_BUFSIZE;
memcpy(&olpClientOverlappedPlusData->ClientAddr, &saRemote, nRemoteLen);
// Associate the accepted socket with the completion port
if(NULL == CreateIoCompletionPort((HANDLE)sClient, hIocp,(ULONG_PTR)0,0) )
{
printf("Error in initialization of Completion Port for server! Press any to exit...");
return -1;
}
/*-- Make Ready to Recive Data From given Port -- */
ret = WSARecv(sClient,&olpClientOverlappedPlusData->wbuf,1,&olpClientOverlappedPlusData->dwBytes,&olpClientOverlappedPlusData->dwFlags,&olpClientOverlappedPlusData->Overlapped, NULL);
}
return 0;
}
DWORD WINAPI ServerWorkerThread(LPVOID CompletionPortID)
{
/*-- Notify Starting of server -- */
printf("\nHello Server Started, I am in worker thread! \n");
HANDLE hIocp = (HANDLE) CompletionPortID;
ULONG_PTR *PerHandleKey;
OVERLAPPED *Overlap;
OVERLAPPEDPLUS *OverlapPlus,*newolp;
DWORD dwBytesXfered;
int ret;
char *strData ;
while (1)
{
ret = GetQueuedCompletionStatus(hIocp,&dwBytesXfered,(PULONG_PTR)&PerHandleKey,&Overlap,INFINITE);
if (ret == 0){
continue;
}
OverlapPlus = CONTAINING_RECORD(Overlap, OVERLAPPEDPLUS, Overlapped);
/*--- Process Data According to Operation Code ---*/
switch (OverlapPlus->nOperationCode )
{
case OP_READ:
// Process the data read Repost the read if necessary, reusing the same receive buffer as before
memset(&OverlapPlus->Overlapped, 0, sizeof(OVERLAPPED));
ret = WSARecv(OverlapPlus->sClient,&OverlapPlus->wbuf,1,&OverlapPlus->dwBytes,&OverlapPlus->dwFlags,&OverlapPlus->Overlapped, NULL);
appendLog((TCHAR*) &OverlapPlus->wbuf.buf[0]);
ZeroMemory(&(OverlapPlus->Overlapped),sizeof(OVERLAPPED));// Why we reset memory ???
printf("\n\n****Inforamtion*****\n\nClient Socket:%d \n Bytes:%d \n Buff :%s \n Client No: %d\n FLAG :%d ",(int)OverlapPlus->sClient,OverlapPlus->dwBytes,OverlapPlus->wbuf.buf,OverlapPlus->nClientNumber,OverlapPlus->dwFlags);
if (ret == SOCKET_ERROR)
{
ret = WSAGetLastError();
if ( ret != WSA_IO_PENDING)
{
// What should i do in case of Error???
//printf("Error occur at WSARecv() : %d", ret);
//ExitThread(0);
break;
}
}
break;
case OP_WRITE:
// Process the data sent, etc.
break;//…
}
}
}
void Initialize()
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 1, 1 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 )
{
printf("\n couldn't find a useable winsock.dll");
exit(1);
}
}
Madhu S. Kapoor
Madhu S. Kapoor
|
|
|
|
|
Hi! I would be most grateful for assistance. I wish to read data from a file into a CByteArray and return the array. So most simplistically, I have tried variants on:
_____
void MyClass::GetData(CString Pathname, int filesize)
{
// get pathname
// get size of file
BYTE* myarray;
myarray=ReadData(Pathname,filesize);
}
//
/////
//
BYTE* MyClass::ReadData(CString Pathname,int filesize)
{
CByteArray array;
array.SetSize(filesize,-1);
FILE* ifile=fopen(Pathname,"rb");
array.SetSize(size);
BYTE *Array = array.GetData();
ZeroMemory(Array,size);
fread(Array,sizeof(BYTE),size,ifile);
//
return Array;
}
//
_______________
I am evidently doing something totally stupid, so would be indebted to anyone who can gently point out what it is and perhaps provide the requisite correction.
Thanks in advance!
Brian
|
|
|
|
|
Do not return the pointer to the variable:
BYTE *Array = array.GetData();
Instead, return an object of some type, or allocate the memory on the heap; i.e, make it static like:
static CByteArray array;
I would rather use simple stuff:
CString strData;<br />
...<br />
return CString;
I myself have never used CByteArray, infact, I don't recall hearing about it.
this is this.
|
|
|
|
|
khan++ wrote: Instead, return an object of some type, or allocate the memory on the heap; i.e, make it static like:
static CByteArray array;
Never do that. What happens if more than one thread calls the function? Disaster
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
You are violating one of the cardinal rules of C and C++ :- Never return a pointer to a local variable. In ReadData , you are calling GetData on a local variable and then returning a pointer to it. array will be destroyed as soon as the function ends, which means you'll be left with a pointer to nowhere.
This will solve that problem.
CByteArray MyClass::ReadData(CString Pathname,int filesize)
{
CByteArray array;
array.SetSize(filesize,-1);
FILE* ifile=fopen(Pathname,"rb");
array.SetSize(size);
BYTE *Array = array.GetData();
ZeroMemory(Array,size);
fread(Array,sizeof(BYTE),size,ifile);
return array;
}
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hi Senthil! Thank you for your response. Violating fundmental principles is, unhappily, a main skill of mine. But when I try the routine as you suggest, I get two compiler errors:
error C2558: class 'CByteArray' : no copy constructor available or copy constructor is declared 'explicit'
is invoked by
return array; // return instance of CByteArray,
while
error C2582: 'operator =' function is unavailable in 'CByteArray'
is invoked by
CByteArray byteArray;
byteArray=GetRawData(Pathname);
Thanks for your patience!
Brian
|
|
|
|
|
hello.
i want to import 3D file in VC++.and then to controll the animation or movement of object by giving values to the object through vc++ program.
thanks.
|
|
|
|
|
well... to keep it simple, u need to use DirectX SDK or OpenGL SDK. If I were in ur place, I wud've used OpenGL-GLUT. google for "GLUT" to know more...
"Do first things first, and second things not at all."
— Peter Drucker.
|
|
|
|
|
hello.
i m new in this field so please help how to get start in
open-gl using it.i should use which functions and how.
and one thing more please tell me is it not possible at all to make movie in 3D and then import in VC++
thanks
|
|
|
|
|
U just check this link for problem with code.
http://www.codeguru.com/forum/showthread.php?t=361063
sf
|
|
|
|
|
how can i override a non-virtual MFC function. it may belong to an MFC class or not. i want to tell linker to execute mine instead of the MFC one.
my program contains an .exe file with 22 DLLs, all linked with MFC as a shared library.
|
|
|
|
|
I believe that you can define your own function with the same name and parameters and return type as the original one, when your class is a descendent of the class whose function you want to override, provided that that function is not internally called by the MFC libraries.
Maybe someone can shed some light on my thoughts above.
If you wanted to override a function for lets say CDialog, then you would subclass it, and implement your own function. But I believe that that function should be in CDialog, not in its some parent in the hierarchy, used by its some other parent, to be effective.
this is this.
|
|
|
|
|
thanx khan for answering me.
let's discuss about ur answer!
1. it's better to use "derived" word. instead of "when your class is a descendent of the class whose function you want to override" it's better to say "when ur class is derived from the class whose function..."
2. when a function is declared as virtual, if it's overriden in the derived class, functions of the base class see it and call it instead of the original one (the function in the base class) while they may think they're really calling the original one.
if the function is not declared as virtual in the base class both classes have their own function with the same prototype. that is functions of base class when call it call the function of base class and function of the derived class when call it call the function of the derived class.
this is what the "virtual" keyword provides.
3. what do u mean by subclassing?
4. u may also use "base" instead of "parent"
i remind my question again. i'm looking for a way for functions of base class to call the function i write instead of what they're linked to. when this member function is not declared as virtual this sounds impossible, but i think there must be a way. besides, there may be a function not belonging to any class and i need to override it.
this may be a linker option or so that when encounters an ambiguity decides which one to use. normally it ignores my code and uses one defined in MFC itself.
when i was programming with BC++ or TC++ some years ago, the linker prefered my code over the original one.
and khan! English seems not to be ur mother tongue like me!
thanks again for ur appreciate and also waiting for other answers
|
|
|
|
|
i new in use mfc grid control by CMaunder
it default cell type is CString, i want to process cell value as int, can some one help me to conver CString to int, or any other sugestion?
|
|
|
|
|
msnet wrote: CMaunder
makes a good class name.
-prakash
|
|
|
|
|