|
You don't handle the WM_PAINT message, in which all the drawing code should be put. You have put everything in WM_CREATE, which is called when the window is being created.
I suggest you read the following article[^] to get a basic understanding of how it works.
|
|
|
|
|
Hi
I am in the process of learning FIX protocol using QuickFix, I am following the example which is given in the documentation,however I am getting an error during build in one file which is part of the quickfix header file.
Can anyone please let me know if I am missing anything in my project configuration. Just as an FYI I did follow all the instruction in quickfix website to set up a C++ project.
Regards
Arup
Error:
---------------------
<br />
1>c:\project\quickfix\quickfix_c\quickfix\include\quickfix\exceptions.h(260) : error C2664: 'FormatMessageW' : cannot convert parameter 5 from 'char [2048]' to 'LPWSTR'<br />
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast<br />
Code of Exceptions.h. The error is in line 260 which is as follows:
<br />
#ifdef _MSC_VER<br />
error = WSAGetLastError();<br />
char buffer[2048];<br />
FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, NULL, error,<br />
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),<br />
buffer, 2048, NULL );<br />
return buffer;<br />
#else<br />
Exceptions.h
-------------------------
<br />
<br />
<br />
<br />
<br />
#ifndef FIX_EXCEPTIONS_H<br />
#define FIX_EXCEPTIONS_H<br />
<br />
#include <string><br />
#include <stdexcept><br />
#include "Utility.h"<br />
<br />
namespace FIX<br />
{<br />
<br />
struct Exception : public std::logic_error<br />
{<br />
Exception( const std::string& t, const std::string& d )<br />
: std::logic_error( d.size() ? t + ": " + d : t ),<br />
type( t ), detail( d )<br />
{}<br />
~Exception() throw() {}<br />
<br />
std::string type;<br />
std::string detail;<br />
};<br />
<br />
struct DataDictionaryNotFound : public Exception<br />
{<br />
DataDictionaryNotFound( const std::string& v, const std::string& what = "" )<br />
: Exception( "Could not find data dictionary", what ),<br />
version( v ) {}<br />
~DataDictionaryNotFound() throw() {}<br />
<br />
std::string version;<br />
};<br />
<br />
struct FieldNotFound : public Exception<br />
{<br />
FieldNotFound( int f = 0, const std::string& what = "" )<br />
: Exception( "Field not found", what ),<br />
field( f ) {}<br />
int field;<br />
};<br />
<br />
struct FieldConvertError : public Exception<br />
{<br />
FieldConvertError( const std::string& what = "" )<br />
: Exception( "Could not convert field", what ) {}<br />
};<br />
<br />
struct MessageParseError : public Exception<br />
{<br />
MessageParseError( const std::string& what = "" )<br />
: Exception( "Could not parse message", what ) {}<br />
};<br />
<br />
struct InvalidMessage : public Exception<br />
{<br />
InvalidMessage( const std::string& what = "" )<br />
: Exception( "Invalid message", what ) {}<br />
};<br />
<br />
struct ConfigError : public Exception<br />
{<br />
ConfigError( const std::string& what = "" )<br />
: Exception( "Configuration failed", what ) {}<br />
};<br />
<br />
struct RuntimeError : public Exception<br />
{<br />
RuntimeError( const std::string& what = "" )<br />
: Exception( "Runtime error", what ) {}<br />
};<br />
<br />
struct InvalidTagNumber : public Exception<br />
{<br />
InvalidTagNumber( int f = 0, const std::string& what = "" )<br />
: Exception( "Invalid tag number", what ),<br />
field( f ) {}<br />
int field;<br />
};<br />
<br />
struct RequiredTagMissing : public Exception<br />
{<br />
RequiredTagMissing( int f = 0, const std::string& what = "" )<br />
: Exception( "Required tag missing", what ),<br />
field( f ) {}<br />
int field;<br />
};<br />
<br />
struct TagNotDefinedForMessage : public Exception<br />
{<br />
TagNotDefinedForMessage( int f = 0, const std::string& what = "" )<br />
: Exception( "Tag not defined for this message type", what ),<br />
field( f ) {}<br />
int field;<br />
};<br />
<br />
struct NoTagValue : public Exception<br />
{<br />
NoTagValue( int f = 0, const std::string& what = "" )<br />
: Exception( "Tag specified without a value", what ),<br />
field( f ) {}<br />
int field;<br />
};<br />
<br />
struct IncorrectTagValue : public Exception<br />
{<br />
IncorrectTagValue( int f = 0, const std::string& what = "" )<br />
: Exception( "Value is incorrect (out of range) for this tag", what ),<br />
field( f ) {}<br />
int field;<br />
};<br />
<br />
struct IncorrectDataFormat : public Exception<br />
{<br />
IncorrectDataFormat( int f = 0, const std::string& what = "" )<br />
: Exception( "Incorrect data format for value", what ),<br />
field( f ) {}<br />
int field;<br />
};<br />
<br />
struct IncorrectMessageStructure : public Exception<br />
{<br />
IncorrectMessageStructure( const std::string& what = "" )<br />
: Exception( "Incorrect message structure", what ) {}<br />
};<br />
<br />
struct DuplicateFieldNumber : public Exception<br />
{<br />
DuplicateFieldNumber( const std::string& what = "" )<br />
: Exception( "Duplicate field number", what ) {}<br />
};<br />
<br />
struct InvalidMessageType : public Exception<br />
{<br />
InvalidMessageType( const std::string& what = "" )<br />
: Exception( "Invalid Message Type", what ) {}<br />
};<br />
<br />
struct UnsupportedMessageType : public Exception<br />
{<br />
UnsupportedMessageType( const std::string& what = "" )<br />
: Exception( "Unsupported Message Type", what ) {}<br />
};<br />
<br />
struct UnsupportedVersion : public Exception<br />
{<br />
UnsupportedVersion( const std::string& what = "" )<br />
: Exception( "Unsupported Version", what ) {}<br />
};<br />
<br />
struct TagOutOfOrder : public Exception<br />
{<br />
TagOutOfOrder( int f = 0, const std::string& what = "" )<br />
: Exception( "Tag specified out of required order", what ),<br />
field( f ) {}<br />
int field;<br />
};<br />
<br />
struct RepeatedTag : public Exception<br />
{<br />
RepeatedTag( int f = 0, const std::string& what = "" )<br />
: Exception( "Repeated tag not part of repeating group", what ),<br />
field( f ) {}<br />
int field;<br />
};<br />
<br />
struct RepeatingGroupCountMismatch : public Exception<br />
{<br />
RepeatingGroupCountMismatch( int f = 0, const std::string& what = "" )<br />
: Exception( "Repeating group count mismatch", what ),<br />
field( f ) {}<br />
int field;<br />
};<br />
<br />
struct DoNotSend : public Exception<br />
{<br />
DoNotSend( const std::string& what = "" )<br />
: Exception( "Do Not Send Message", what ) {}<br />
};<br />
<br />
struct RejectLogon : public Exception<br />
{<br />
RejectLogon( const std::string& what = "" )<br />
: Exception( "Rejected Logon Attempt", what ) {}<br />
};<br />
<br />
struct SessionNotFound : public Exception<br />
{<br />
SessionNotFound( const std::string& what = "" )<br />
: Exception( "Session Not Found", what ) {}<br />
};<br />
<br />
struct IOException : public Exception<br />
{<br />
IOException( const std::string& what = "" )<br />
: Exception( "IO Error", what ) {}<br />
};<br />
<br />
struct SocketException : public Exception<br />
{<br />
SocketException()<br />
: Exception( "Socket Error", errorToWhat() ) {}<br />
<br />
SocketException( const std::string& what )<br />
: Exception( "Socket Error", what ) {}<br />
<br />
std::string errorToWhat()<br />
{<br />
#ifdef _MSC_VER<br />
error = WSAGetLastError();<br />
char buffer[2048];<br />
FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, NULL, error,<br />
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),<br />
buffer, 2048, NULL );<br />
return buffer;<br />
#else<br />
error = errno;<br />
return strerror( error );<br />
#endif<br />
}<br />
<br />
int error;<br />
};<br />
<br />
struct SocketSendFailed : public SocketException<br />
{<br />
SocketSendFailed() {}<br />
SocketSendFailed( const std::string& what )<br />
: SocketException( what ) {}<br />
};<br />
<br />
struct SocketRecvFailed : public SocketException<br />
{<br />
SocketRecvFailed( int size )<br />
: SocketException( size == 0 ? "Connection reset by peer." : size < 0 ? errorToWhat() : "Success." ) {}<br />
SocketRecvFailed( const std::string& what )<br />
: SocketException( what ) {}<br />
};<br />
<br />
struct SocketCloseFailed : public SocketException<br />
{<br />
SocketCloseFailed() {}<br />
SocketCloseFailed( const std::string& what )<br />
: SocketException( what ) {}<br />
};<br />
<br />
<br />
}<br />
<br />
#endif //FIX_EXCEPTIONS_H<br />
<br />
|
|
|
|
|
The posting of all that code was unnecessary. You simply have a Unicode issue. See here for more.
"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
|
|
|
|
|
The important bit is the error message:
"c:\project\quickfix\quickfix_c\quickfix\include\quickfix\exceptions.h(260) : error C2664: 'FormatMessageW' : cannot convert parameter 5 from 'char [2048]' to 'LPWSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast"
It looks like you're compiling your code with _UNICODE defined. When that happens FormatMessage gets replaced by FormatMessageW which expects it's parameters to be wide characters. As rest of the code seems to be assuming that they're using narrow characters there's a type mismatch.
If Visual Studio check that for the project you've selected "use multi-byte character set" rather than "use unicode character set" and the problem will go away. You might like to also contact the programmers that maintain the library you're using and suggest they document the problem (or switch their code to use wide characters as narrow ones have been dead on Windows for some time now).
Cheers,
Ash
|
|
|
|
|
Please mark this code as Resolved. I would like to thank all for helping me out.
|
|
|
|
|
Hi,
I am getting the following error when I am building my project in Visual Studio 2005.
Error 134 error C2440: 'static_cast' : cannot convert from 'LRESULT (__thiscall CCancelUIThread::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)' d:\CBSTellerLatest\IDManager\CancelThread.cpp 138
I am not getting any error when I runm the same code on Visual Studio 6.0
The Code is as Follows
Code in .H file
afx_msg LRESULT OnStepProgress(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnSetText(WPARAM wParam, LPARAM lParam);
Code in .CPP file
BEGIN_MESSAGE_MAP(CCancelUIThread, CWinThread)
ON_MESSAGE(CM_PROGRESS_STEPIT, OnStepProgress)
ON_MESSAGE(CM_PROGRESS_SETTEXT, OnSetText)
END_MESSAGE_MAP()
And the function definations.
Please help me out.
Thanks In Advance
|
|
|
|
|
What is line 138?
Have you tried:
ON_MESSAGE(CM_PROGRESS_STEPIT, &CCancelUIThread::OnStepProgress)
"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
|
|
|
|
|
Ummm - a CWinThread is not a CWnd, so it can't have ON_MESSAGE handlers. It *can* have ON_THREAD_MESSAGE handlers, though…so use those instead...
The reason VC6 doesn't complain is that its compiler is so lax at checking and enforcing static typing rules. That's a bad thing, m'kay, 'cause it means there can be many latent, potential bugs left in your code.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
CodeProject MVP for 2010 - who'd'a thunk it!
|
|
|
|
|
Hi All,
I had Extracted a DLL from a CAB file(Installation package) and edited it using VS2005 to translate some captions in String Table from English to French language(for testing my installation package to support other language) and Saved.
Using the above DLL we are re-creating a Translated Kit(Installation package) and installed it in a fresh machine, After successful installation of my software, While trying to access the above mentioned translated DLL, MFC crash occurs.
The same DLL(Compiled and Build using existing source code in VS2005) with all above actions(translating the string table entries)is working fine.
Can anybody tell me what i am missing / anybody faced similar kind of issue?
Note: I had tried accessing other DLLs to translate the string table entries and corresponding DLLs are accessed without any errors.Also The project properties of both the DLLs(Working/Not Working) are similar.
Thanks in advance.
Thirumalesh
Never Never Never Give Up!
|
|
|
|
|
Hi, I want to Automate MS Word 2010 to extract text with the following code. but I get run-time error "A null reference pointer was passed to the stub."
am I doing something wrong?
CString strDocFile(L"C:\\a.doc");
COleVariant covTrue((short)TRUE), covFalse((short)FALSE), covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
CApplication appObj;
if(!appObj.CreateDispatch(L"Word.Application"))
{
AfxMessageBox(L"could Not Create The Application Object");
return;
}
appObj.put_Visible(FALSE);
CDocuments docsObj(appObj.get_Documents());
CDocument0 docObj;
COleVariant oleStrFile(strDocFile.GetString(),VT_BSTR);
LPDISPATCH pIDoc = docsObj.Open(
oleStrFile,
covFalse,
covFalse,
covFalse,
covOptional,
covOptional,
covFalse,
covOptional,
covOptional,
covOptional,
covOptional,
covTrue,
covOptional,
(long)0,
covOptional,
covFalse
);
docObj.AttachDispatch(pIDoc);
docObj.Activate();
docObj.Select();
CSelection selObj(appObj.get_Selection());
CString docText = selObj.get_Text();
docObj.Close(covOptional, covOptional, covOptional);
docsObj.Close(covOptional, covOptional, covOptional);
appObj.Quit(covOptional, covOptional, covOptional);
modified on Friday, July 9, 2010 8:48 AM
|
|
|
|
|
Is part of the quiz guessing on what line the error occurs?
My guess is that the file L"C:\a.doc" does not exist, and Open fails which sends a null reference to AttachDispatch.
Have you tried opening the file named L"C:\\a.doc" instead?
You don't seem to like checking on return values much.
|
|
|
|
|
Of course I miss type that in the forum, in my program i retreve the filename from CFileDialog.
I ame sure of file path and file existance.
|
|
|
|
|
So what about checking return values?
|
|
|
|
|
Of course I did , I just simplify the code for the forum, the open method of CDocuments throw the exception and I use the following method instead of Open and It works correctly but again I don't know why the previous one doesn’t work.
LPDISPATCH pIDoc = docsObj.Open2000(
oleStrFile,
covFalse,
covFalse,
covFalse,
covOptional,
covOptional,
covFalse,
covOptional,
covOptional,
covOptional,
covOptional,
covTrue
);
|
|
|
|
|
From what I can find[^]
this
covOptional,
(long)0,
covOptional,
covFalse
should be this
covOptional,
covOptional,
(long)0,
covOptional,
|
|
|
|
|
Of course what you mentioned is related to older versions of office type libraries
What i used is Microsoft Word 14.0 Object Library <8.5> which has diffrent interface for Open Method, and OpenConflictDocument parameter is not supported.
But there are other alternative open methods that implement older parameters, Like:
docsObj.OpenOld(...)
docsObj.Open2000(...)
docsObj.Open2002(...)
the last one is what you mentioned but it result in error too.
Only the Open2000(...) method work with out problem but it doesnot support docx documents.
|
|
|
|
|
Hi,
I am tring to pass a structure from one process to another process via file mapping (shared memory).
I am able to get all varibales but unable to get the pointer value defined in dirrerent process.
I think memory addresses are relative to local to that process...How can I access same memory in diffrent process.
|
|
|
|
|
You are correct that addresses are only valid in the context of its process. You would have to put that data into shared memory as well.
|
|
|
|
|
|
Have a look at Ash's reply on serializing data below.
|
|
|
|
|
Creating shared memory is the right way, so different processes and communicate in a secure way.
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
You have to work out how you're going to marshal (as in railway marshalling, not US law enforcement officer) your data from one process to another.
Generally you have an intermediate form that you write into your shared memory and then read out again in the other process. Say you have a class:
class A
{
public:
std::string text_;
};
You can't just use something like placement new, copy it into the shared memory and expect it to work. The string's characters could be anywhere in the source address space. One solution is to treat the shared memory like a file - you can write the characters and how many of them there are into the shared memory and read them out on the other side:
class A
{
public:
std::string text_;
void raw_memory_write( void *where );
void raw_memory_read( void *where );
};
Once you've implemented this pair you have to work out how to signal the other process that there's an object to read AND, if you want bidirectional comms, avoid writing to the same memory (you can use two blocks for this, one for each process to write into and the other to read from). While there are ways of doing this if you don't know what you're doing it can backfire horribly.
An alternative to using shared memory is to use an interprocess comms mechanism that's already out there and works. For example sockets if it has to be portable. That way all you have to worry about is reading/writing a stream of bytes from something that looks surprisingly like a file. And it's less code to write a simple sockets client/server pair than manage all the detritus around shared memory.
Cheers,
Ash
|
|
|
|
|
In my project I use many dialogbars allowing it to be docked and undocked.
I need to change the dialogbars size according to some runtime conditions and it works but,
when I dock or undock the dialog bar it restores the initial size or, when I dock another bar close to the resized bar, it consider the initial size and not the new one.
Does someone one know how to let dialogbar resize operation work properly ?
Thanks a lot !
|
|
|
|
|
How to add check mark in front of selected item in listbox in MFC..
Can anyone help me how to do this..
Thanks..
|
|
|
|
|
use
CCheckListBox .
I hope it will help you.
|
|
|
|
|