|
hi friends,
class MyEchoSocket : public CAsyncSocket
{
public:
virtual void OnAccept(int nErrorCode);
virtual void OnClose(int nErrorCode);
virtual void OnConnect(int nErrorCode);
virtual void OnOutOfBandData(int nErrorCode);
virtual void OnReceive(int nErrorCode);
virtual void OnSend(int nErrorCode);
};
class CServerDlg : : public CDialog
{
public:
void OnReceive();
void OnClose();
void OnAccept();
void OnSent();
CSolusServerDlg(CWnd* pParent = NULL); // standard constructor
};
void CServerDlg::OnAccept()
{
CString strIP;
UINT port;
if(m_sListener.Accept(m_sConnected))
{
m_sConnected.GetPeerName(strIP,port);
m_status = strIP ;
UpdateData(FALSE);
}
else
{
AfxMessageBox("Cannot Accept Connection");
}
}
this above code is crasing 2nd client accepting or multiple client trying to connect
please help me...
|
|
|
|
|
Member 3653751 wrote: this above code is crasing...
Which is fairly meaningless given that you've provided no context, or stated exactly what is happening. By "crash" do you mean an exception is thrown, an assertion is fired, or something else? Please elaborate. Have you used the debugger to narrow the problem down?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Debug asseration Failed...
Program:c:\bujji\server\Debug\server.exe
file : sockcoare.cpp
line: 177
for more information on how your program can cause an asseration failure,
see the vusial c++ Documentation on asserts.
please help
|
|
|
|
|
Member 3653751 wrote: file : sockcoare.cpp
line: 177
Locate the source file, and take a look at line 177 to see which condition is failing. That should get you started.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
Hello guys,
I'm trying to write a funtion to read a simple bitmap, but I've encountered a serious problem.
As model I used the description of the bitmap file format from wikipedia http://en.wikipedia.org/wiki/BMP_file_format[^] and as far as I know this is definitely the correct format.
I also used the same 2x2 24-bit bitmap[^] to test my function, but except for the first value (the magic number or identifier) all other read values are wrong.
#include <stdint.h>
#include <stdio.h>
typedef uint8_t BYTE;
typedef uint16_t BYTE2;
typedef uint32_t BYTE4;
typedef struct BMP_FILE_HEADER
{
BYTE2 MagicNumber;
BYTE4 FileSize;
BYTE2 Reserved1;
BYTE2 Reserved2;
BYTE4 Offset;
} BMP_FILE_HEADER;
typedef struct BMP_INFO_HEADER
{
BYTE4 HeaderSize;
BYTE4 ImageWidth;
BYTE4 ImageHeight;
BYTE2 NumberOfColorPanels;
BYTE2 ColorDepth;
BYTE4 Compression;
BYTE4 ImageSize;
BYTE4 HorizontalResolution;
BYTE4 VerticalResolution;
BYTE4 NumberOfColors;
BYTE4 NumberOfImportantColors;
} BMP_INFO_HEADER;
typedef struct BITMAP
{
BMP_FILE_HEADER bmpFileHeader;
BMP_INFO_HEADER bmpInfoHeader;
BYTE* bmpData;
} BITMAP;
#define BI_RGB 0
#define BI_RLE8 1
#define BI_RLE4 2
#define BI_BITFIELDS 3
#define BI_JPEG 4
#define BI_PNG 5
BITMAP readbmp(const char* _pcFileName)
{
FILE* bmp = fopen(_pcFileName, "rb");
BITMAP bitmap;
fread(&bitmap.bmpFileHeader, sizeof(BMP_FILE_HEADER), 1, bmp);
fread(&bitmap.bmpInfoHeader, sizeof(BMP_INFO_HEADER), 1, bmp);
fseek(bmp, bitmap.bmpFileHeader.Offset, SEEK_SET);
bitmap.bmpData = (BYTE*)malloc(bitmap.bmpInfoHeader.ImageSize);
fread(bitmap.bmpData, bitmap.bmpInfoHeader.ImageSize, 1, bmp);
fclose(bmp);
return bitmap;
}
To test my function i wrote a short program, which reads the above mentioned bitmap.
#include <iostream>
#include "readbmp.h"
#define DBG(x) (cout << #x << "\t:\t" << (x) << endl)
using namespace std;
int main(void)
{
BITMAP myBmp;
myBmp = readbmp("..\\bmp24.bmp");
DBG(myBmp.bmpFileHeader.MagicNumber);
DBG(myBmp.bmpFileHeader.FileSize);
DBG(myBmp.bmpFileHeader.Reserved1);
DBG(myBmp.bmpFileHeader.Reserved2);
DBG(myBmp.bmpFileHeader.Offset);
DBG(myBmp.bmpInfoHeader.HeaderSize);
DBG(myBmp.bmpInfoHeader.ImageWidth);
DBG(myBmp.bmpInfoHeader.ImageHeight);
DBG(myBmp.bmpInfoHeader.NumberOfColorPanels);
DBG(myBmp.bmpInfoHeader.ColorDepth);
DBG(myBmp.bmpInfoHeader.Compression);
DBG(myBmp.bmpInfoHeader.ImageSize);
DBG(myBmp.bmpInfoHeader.HorizontalResolution);
DBG(myBmp.bmpInfoHeader.VerticalResolution);
DBG(myBmp.bmpInfoHeader.NumberOfColors);
DBG(myBmp.bmpInfoHeader.NumberOfImportantColors);
cin.get();
return 0;
}
This code just writes out the header informations as following:
myBmp.bmpFileHeader.MagicNumber : 19778
myBmp.bmpFileHeader.FileSize : 0
myBmp.bmpFileHeader.Reserved1 : 0
myBmp.bmpFileHeader.Reserved2 : 54
myBmp.bmpFileHeader.Offset : 2621440
myBmp.bmpInfoHeader.HeaderSize : 131072
myBmp.bmpInfoHeader.ImageWidth : 131072
myBmp.bmpInfoHeader.ImageHeight : 65536
myBmp.bmpInfoHeader.NumberOfColorPanels : 24
myBmp.bmpInfoHeader.ColorDepth : 0
myBmp.bmpInfoHeader.Compression : 0
myBmp.bmpInfoHeader.ImageSize : 247660544
myBmp.bmpInfoHeader.HorizontalResolution : 247660544
myBmp.bmpInfoHeader.VerticalResolution : 0
myBmp.bmpInfoHeader.NumberOfColors : 0
myBmp.bmpInfoHeader.NumberOfImportantColors : 0
What am I doing wrong? It looks as if the parameters are in a wrong order, even though I used the one described on wikipedia.
Thanks for your help.
|
|
|
|
|
This is because the compiler will add padding-zeros in the structure to align the different members on a specific boundary. You can read more about the subject here[^] (or google to find additional information).
To disable that, you have to pack your structure on a 1 byte boundary using #pragma pack(1) . See here[^].
On the other hand, why are you writing the code to read a bitmap ? There are already quite some libraries which can do that, so why reinventing the wheel ? (unless for learning purpose, in which case it is understandable).
|
|
|
|
|
Learning purpose ... not really. I know that there are a lot of libraries out there, which can load bitmaps. Actually I was just bored to death and wanted to do something. And I wanted a bitmap structure/class which gives me full control over all parameters and single values.
Oh, and thanks, the parameters are now displayed correctly. There is just one thing I do not understand: The value which contains the image size is always 0x00.
|
|
|
|
|
Manfr3d wrote: There is just one thing I do not understand: The value which contains the image size is always 0x00 It may be you won't need to use image-size, just width and height, and so don't need to worry too much about it. A quick search of (a limited amount of) code on my laptop that deals with bitmaps did not find it being used. Though Width and Height occur all the time as in a call to, for example, the Win32 function:
BitBlt(hDC,xDest,yDest,bmInfo.biWidth,bmInfo.biHeight,hDCMem,0,0,SRCCOPY);
|
|
|
|
|
Yeah, I think you're right. However, the image size would make memory allocation easier.
|
|
|
|
|
I am having a sample Console based application Test.dsw which uses .C files. The application start point is the file shown below.
//GLGMain.h
/*---------------------------------------------------------------------------
| This file defines platform-specific entry point and may be included when
| the generic GLG API is used.*/
#include "GlgApi.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Prototype for GlgMain */
int GlgMain _G_PROTO(( int, char*[], GlgAppContext ));
#ifdef __cplusplus
}
#endif
#ifdef MS_WINDOWS
#include <windows.h>
/* MS Windows entry point. */
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow )
{
GlgAppContext AppContext; GlgObject args_array; int rval; GlgLong argc;
char ** argv;
args_array = GlgParseArgs( "GlgToolkit", lpCmdLine, &argc, &argv );
AppContext = GlgInit( False, (GlgAppContext)hInstance, argc, argv );
rval = GlgMain( (int) argc, argv, AppContext );
GlgDropObject( args_array ); GlgTerminate(); return rval;
}
#else /* X Windows *//* X Windows entry point. */#ifdef _G_USE_PROTOTYPES
int main( int argc, char *argv[] )#elseint main( argc, argv ) int argc;
char *argv[];#endif{ return GlgMain( argc, argv, (GlgAppContext)0 );}
#endif
The main functionality of the application is present in the file diagramG.C.
I want to convert the application to MFC Based application and use the diagramG.C file in my application. When I tried to create a MFC EXE application and included the diagramG.C file in my project and started compiling its giving me errors. kindly advise.
Anyone kindly tell me the step by step procedure to use the diagramG.C file in my MFC based application and change the starting point of the application from int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow ) to MFC starting point.
Thanks in advance
|
|
|
|
|
manoharbalu wrote: started compiling its giving me errors
What are those errors?
|
|
|
|
|
manoharbalu wrote: and change the starting point of the application from int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow ) to MFC starting point.
I would take the opposite route: let Visual Studio generate the MFC application skeleton for you and then add your files to it.
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]
|
|
|
|
|
Please, read the posting guidelines before posting. When posting code, use the pre tags to format your code properly.
Now to your question: there's no magic way to convert from a console application to a MFC application. You'll need to understand how MFC works and refactor parts of your code. What has to be modified highly depends on your specific application, there's no generic way to do something like that.
So, if you never worked with MFC before, I strongly suggest you start by reading a good book on the subject, it will make you gain a lot of time in the near future.
|
|
|
|
|
I'd second Carlo's suggestion (in spite of the fact that he can be an annoying prick at times).
Simply use the wizard to generate the MFC project of desired type (dialog, SDI, etc.,) and add code from your console application as applicable. Can't be easier than this.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
Rajesh R Subramanian wrote: Carlo's suggestion (in spite of the fact that he can be an annoying prick at times).
Oh, thank you, my good friend...
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]
|
|
|
|
|
You're welcome!
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
Created several Controls in my GUI, but all of them have Bold text.
How do you disable it, so Windows displays them as Regular text?
|
|
|
|
|
By default, your controls have the SYSTEM_FONT set as font to them, if you want to change that you should use WM_SETFONT[^] to give them a different font. See here[^] for some additional information, just look for SYSTEM_FONT on the page, and be sure to read the remarks section.
p.s: You can use CreateFont[^] and/or CreateFontIndirect[^] to create fonts.
> 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. <
|
|
|
|
|
This does not happen spontaneously. What technology are you using, I mean what do you use to design your control? Next time try supplying some more information, your question's subject 'Win32/C++' is not exactly limpid.
|
|
|
|
|
Fareed Rizkalla wrote: Created several Controls in my GUI, but all of them have Bold text.
How do you disable it, so Windows displays them as Regular text?
Query:
1. Have you assigned any FONT object to your control? if YES, you need to look into it property.
IF not, check you window desktop display or ZOOM, that might be causing problem
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
So, here is the thing:
for example i got a function which reads a file line by line and outputs each line to a console.
My file got 10 lines of text. Now i want to implement multithreading. i can use, for example,
int total_nr_of_threads = 7;
create max up to 7 threads and each thread will be responsible for reading some line from text file starting from the very 1st line and outputs data. And then for example when 1st thread finishes, it checks which line hasnt been read and read it and then outputs data. So how can i implement this? How to check if some line has been already read by some thread and another thread will not read it again?
I'm confused about the algorithm, just got stuck with it
Thanks in advance.
|
|
|
|
|
Thread synchronization is a big topic, have a look at MSDN [^].
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]
|
|
|
|
|
Alright! Thanks for the link Thats exactly what i need.
|
|
|
|
|
You could create an array of 8 threads 0..7, iterate in a loop and have the threads read a line each.
Remember to lock the critical section when a thread accesses line.
While (count<10)
{
myThread[threadCount].readLineInto(myLineArray[count]);
threadCount++;if(threadCount>7) threadCount=0;
count++;
}
CCriticalSection cs;
cs.Lock();
cs.Unlock();
....
cs.Lock();
cs.Unlock();
Synchronized multi-threading in C++ (No MFC!)
Synchronized multi-threading in C++ (No MFC!)
class MyThread : public Thread {
private:
int m_nCount;
public:
MyThread(int n,const char* nm) {
Thread::setName(nm);
m_nCount = n;
}
void run() {
for(int i=0;i<m_nCount;i++) {
cout << getName().c_str() << ":" << i << endl;
}
}
};
int main() {
Thread *t1 = new MyThread(15,"Thread 01");
Thread *t2 = new MyThread(10,"Thread 02");
try {
t1->start();
t2->start();
t1->stop();
t2->stop();
}catch(ThreadException ex) {
printf("%s\n",ex.getMessage().c_str());
}
delete t1;
delete t2;
return 0;
|
|
|
|
|
csrss wrote: So how can i implement this? How to check if some line has been already read by some thread and another thread will not read it again?
Critical Section and a User defined DataStructure is needed here
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|