|
|
|
|
thank you Snakefoot, I finish it;
|
|
|
|
|
Hi, I am building an application using the OGRE 3D engine and Rebecca API for AIML. The problem is when creating a NetworkAimlFacade object. Its constructors need the "int argc, char* args[]" that are normally in the main method. But I'm not using any main method and I am building an independent class based on a sample console application:
Here is my class:
class ChatBot
{
private:
NetworkGraphBuilder* builder;
public:
ChatBot(){
NetworkAimlFacade aiml(argc, args);
NetworkGraphBuilder &builder = aiml.getNetworkGraphBuilder();
string botName = builder.getBotPredicate("name").c_str();
StringPimpl response = builder.getResponse("connect");
}
string askQuestionAndGetAnswer( string input )
{
StringPimpl strPimText;
builder->getResponse(strPimText);
string responseString = strPimText.c_str();
return (responseString);
}
};
Here is part of the console sample:
int main (int argc, char* args[])
{
NetworkAimlFacade aiml(argc, args);
Can anyone tell me if it is possible to initialize the "argc" and "args" variables with out the main method? (I've tried a couple of ways but they don't work ![Frown | :(](https://codeproject.global.ssl.fastly.net/script/Forums/Images/smiley_frown.gif)
|
|
|
|
|
try another signatures in Constructor ..is it possible ??
|
|
|
|
|
argc and argv together define an array of strings. Typically they are used to pass arguments from command line to an application but it is not necessary that arguments should come from command line.
In the context of NetworkAimlFacade, just think of a class with constructor taking two arguments. First is the size of an array and second argument is the pointer to array. Read the NetworkAimlFacade documentation to see what parameters does it except. If it is the case that it can work with default settings, when no arguments are passes then you use NetworkAimlFacade aiml(0, 0);
-Saurabh
|
|
|
|
|
To get the entire command line for a process use the GetCommandLine[^] API.
To convert the command line to an array similar to argv, use the CommandLineToArgvW[^] API.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Largo65 wrote: But I'm not using any main method
So how do you run the program?
Largo65 wrote: ChatBot(){
NetworkAimlFacade aiml(argc, args); // Where can I get these vars?
The ChatBot() constructor takes no parameters, and yet within the constructor you have the statement NetworkAimlFacade aiml(argc, args); . You need to present these paramaeters to the constructor thus: ChatBot(int argc, char** args) .
|
|
|
|
|
Hi everyone,
Quick question about inline assembler with C++ code.
I was just wondering if, when using inline assembler in a class method, it is necessary to push all registers I am going to use onto the stack and then pop them off after I'm done. I thought this might be necessary because the C compiler might require their contents after the _asm{} code execution.
For example;
void MyClass::MyFunction(){
int a, b, c; // for example
// maybe have some C code here
_asm{
// *
// assembler code using a number of registers (eax, ebx, ecx, for example)
// **
}
// maybe have some more C code here
}
My question is: should I push (at //*) those registers I'm going to utilize, and then pop them (at //**) in the above code.
Help would be much appreciated.
Many thanks,
Paul
|
|
|
|
|
Generally for the AX/BX/CX/DX/SI/DI registers, no. All others (BP, segment registers, etc...) yes. Depends on the compiler really.
-- Ian
|
|
|
|
|
I disagree with the other answer. I think that, yes, you should push and pop any registers that you are going to touch. The compiler will take care of the rest automatically.
As an exercise, you should turn assembly code listings on for a small project and examine some of the code emitted by the compiler. In can be very educational for things like this.
-edit- if you have doubts then comment off the push and pops and see what happens. The phrase "unexpected results" comes to mind. However, if you change ECX without restoring it the results will be not unexpected - the app will most likely crash since the this pointer is different.
|
|
|
|
|
Hi All,
I have a problem with LoadImage method in my small Visual C++ project in Visual Studio 2008. No matter what I pass as filename, The GetLastError always returns "The System Cannot find the File Specified".
I've tried with Loading from the resource:
m_pBitmap->LoadBitmap(IDB_BITMAP1); //THIS WORKS PERFECTLY
But I've commented out this line and instead using the following code in OnInitialUpdate() method. But It fails. I've placed the bmp file in C: also in the Debug directory from where I run the executable. (While running from Debug the filename is simply "barcode.bmp" and I've placed the bmp file in the Debug directory.)
But I always get the error: The System Cannot find the File Specified. Definitely, I'm missing something but I'm unable to find out....
----------------------------------------------------------------------------------
void CMymfcBitmapView::OnInitialUpdate()
{
.
.
.
//m_hBitmap is a HBITMAP Member Variable in the my View Class
m_hBitmap = (HBITMAP)LoadImage(NULL, (LPCWSTR)"c:\\barcode.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
if(m_hBitmap == NULL)
{
//DWORD err = ::GetLastError();
LPVOID lpMsgBuf;
::FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL);
::MessageBox( NULL, (LPCTSTR)lpMsgBuf, (LPCWSTR)"Error", MB_OK | MB_ICONINFORMATION );
// Free the buffer.
LocalFree( lpMsgBuf );
}
--------------------------------------------------
Thanking you all in Advance....
|
|
|
|
|
raich wrote: m_hBitmap = (HBITMAP)LoadImage(NULL, (LPCWSTR)"c:\\barcode.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
Is the LPCWSTR cast necessary?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Otherwise my compiler complains...
------------------------------------------
error C2664: 'LoadImageW' : cannot convert parameter 2 from 'char *' to 'LPCWSTR'
And It shows LoadImageW!!
------------------------------------------
Casting with (LPCWSTR) at least made my code compilation error free....
|
|
|
|
|
raich wrote: Casting with (LPCWSTR) at least made my code compilation error free....
But that does not always mean it's the right thing to do. Have you tried prefacing the string literal with an L ?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
This error C2664 predicts your runtime error; this is the reason.
You should change the path encoding from ascii to unicode.
|
|
|
|
|
I'd say you're passing an Ansi string to something expecting Unicode (ie: wide strings).
Try:
L"C:\\barcode.bmp" or
_T("C:\\barcode.bmp")
-- Ian
|
|
|
|
|
Thank you Ian...It worked
And David thanks to you also....
|
|
|
|
|
raich wrote: m_hBitmap = (HBITMAP)LoadImage(NULL, (LPCWSTR)"c:\\barcode.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
Should be (as implicitely suggested by David)
m_hBitmap = (HBITMAP)LoadImage(NULL, _T("c:\\barcode.bmp"),IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
[added]
Well, not the fastest post of my life, I guess...
[/added]
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]
|
|
|
|
|
Hi all,
As you probably know, there is a problem with CString types in CList, CMap or CArray with regards to serialization. I have attempted to remedy this by overriding void AFXAPI SerializeElements. Before I post my code though, I'd like to ask if any other MFC container class can serialize CStrings correctly, for example CTypedPtrList? I'm not real particular on the container class for my current app and figuring out the peculiarities of serialize is exhausting.
The problem with the code below is that even after overriding SerializeElements, I get a mem copy error when doing a serialize load operation. A breakpoint in SerializeElements is never hit so for some reason it's not being used. I also have a serialize() function for the base class elements but it's not used either, presumably because all base elements are CSTRINGs? There are 2 classes, one for the base elements and another with the CList and functions. BTW, the functions that save and load the list are called from inside the Doc class serialize function.
Thanks in advance -
///////.h file
class CChartInfo : public CObject
{
DECLARE_SERIAL(CChartInfo)
public:
CString m_ChartName;
CString m_Portfolio;
CString m_DataPath;
CString m_DataFile;
CChartInfo(const CChartInfo &s)
{m_ChartName = s.m_ChartName;
m_Portfolio = s.m_Portfolio;
m_DataPath = s.m_DataPath;
m_DataFile = s.m_DataFile;}
CChartInfo& operator=(const CChartInfo &s)
{m_ChartName = s.m_ChartName;
m_Portfolio = s.m_Portfolio;
m_DataPath = s.m_DataPath;
m_DataFile = s.m_DataFile;
return *this;}
public:
void Serialize(CArchive& ar);
public:
CChartInfo();
virtual ~CChartInfo();
};
class CChartManager : public CObject
{
DECLARE_SERIAL(CChartManager)
public:
CList<cchartinfo, cchartinfo&=""> m_ChartList;
void AddChart(CChartInfo ChartInfo);
bool GetChart(CString ChartName, CChartInfo &ChartInfo);
bool LoadChartList();
bool SaveChartList();
CChartManager();
virtual ~CChartManager();
};
void AFXAPI SerializeElements(CArchive& ar,CChartInfo* pChartInfo, int nCount);
////////////////////////////////////////.cpp file
IMPLEMENT_SERIAL(CChartInfo, CObject, VERSION_NUMBER)
IMPLEMENT_SERIAL(CChartManager, CObject, VERSION_NUMBER)
CChartInfo::CChartInfo()
{
}
CChartInfo::~CChartInfo()
{
}
void CChartInfo::Serialize(CArchive& ar)
{
CObject::Serialize(ar);
if (ar.IsStoring()){
ar << m_ChartName
<< m_Portfolio
<< m_DataPath
<< m_DataFile;
}
else{
ar >> m_ChartName
>> m_Portfolio
>> m_DataPath
>> m_DataFile;
}
}
CChartManager::CChartManager()
{
}
CChartManager::~CChartManager()
{
}
// CChartManager member functions
bool CChartManager::SaveChartList()
{
//assumes m_ChartList has been loaded with correct data
char acPath[256];
if ( GetModuleFileName( NULL, acPath, 256 ) != 0) {
// guaranteed file name of at least one character after path
* ( strrchr( acPath, '\\' ) + 1 ) = '\0';
//AfxMessageBox( acPath ); // Use it
}
strcat(acPath, "ChartManager.dat");
CFile ChartManagerFile;
CFileException Err;
if (ChartManagerFile.Open(acPath, CFile::modeCreate | CFile::modeWrite, &Err))
{
CArchive archive(&ChartManagerFile, CArchive::store);
m_ChartList.Serialize(archive);
archive.Close();
ChartManagerFile.Close();
return 1;
}
else {
Err.ReportError();//for debug only
return 0;
}
}
bool CChartManager::LoadChartList()
{
//read chartlist file and load data into list
//if file not found returns false
m_ChartList.RemoveAll();
char acPath[256];
if ( GetModuleFileName( NULL, acPath, 256 ) != 0) {
// guaranteed file name of at least one character after path
* ( strrchr( acPath, '\\' ) + 1 ) = '\0';
//AfxMessageBox( acPath ); // Use it
}
strcat(acPath, "ChartManager.dat");
CFile ChartManagerFile;
CFileException Err;
if (ChartManagerFile.Open(acPath, CFile::modeRead, &Err))
{
CArchive archive(&ChartManagerFile, CArchive::load);
m_ChartList.Serialize(archive);
archive.Close();
ChartManagerFile.Close();
return 1;
}
else {
Err.ReportError();//for debug only
return 0;
}
}
void AFXAPI SerializeElements(CArchive& ar, CChartInfo* pChartInfo, int nCount)
{
for(int i=0;nCount;i++,pChartInfo++)
{
pChartInfo->Serialize(ar);
}
}
modified on Wednesday, September 23, 2009 3:09 PM
|
|
|
|
|
Ok,
I put a breakpoint inside the MS version of SerializeElements and it hit. So as suspected my version is not being used.
I guess I don't really understand how to override SerializeElements so the code uses my version. What are the rules?
The CList is still required to use .Serialize() of course.
Thanks
modified on Wednesday, September 23, 2009 4:38 PM
|
|
|
|
|
Ok,
Need to review Templates. You have to make the template explicit by adding the class name before (.
|
|
|
|
|
Is it possible to make the shell notify you when the user opens a folder and eventually prevent it? I am trying to build a folder guard app. Notification objects does not seem to cover this functionality. The ICopyHook interface also seems like not the solution. Any suggestions will be highly appreciated.
Martin
|
|
|
|
|
Have you read through Michael Dunn's Shell-related articles?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|