我使用了CLIPS6.30版本,我将CLIPS嵌入VC ++的方式就像“advance.doc”中显示的wrappedDLLExample(使用CLIPSWind32.lib和CLIPSWin32CPP.lib)。
当我写一个类myCLIPSCPPRouter时,我需要比较logicalNames.But函数“strcmp”不起作用。代码行被跳过了。
int myCLIPSRouter::Query(CLIPSEnv *cEnv,char *logicalName)
{
int n = strcmp(logicalName,m_lName); //Line (1)
if(strcmp(logicalName,m_lName) == 0)
return TRUE;
else
return FALSE;
}
第(1)行将始终发货。并且无论这两个字符串(logicalName和m_lName)是否相同,它都会到达函数的末尾,即不执行“strcmp()”。所以很奇怪*!(我写道“以前就回归'FALSE'。这是错误的。”)* 这两个字符串没有错误。我已经将两者都改为“abc”,并没有什么区别。
我尝试过其他方法,比如将char *转换为CString,然后调用str.compareNoCase()。但它也被跳过了。
我想也许我使用CLIPSRouter的方式是错误的。我只想说明CLIPS“打印输出”可以显示在Dialog的编辑框上。如果您熟悉CLIPS集成,请告诉我正确的方法。非常非常感谢!!!!
答案 0 :(得分:1)
It looks like you're using a beta version of CLIPS 6.30 rather than the release version (clips_windows_projects_630.zip from http://sourceforge.net/projects/clipsrules/files/CLIPS/6.30/). The DLL doesn't expose the router functionality, so it's unclear how you could get your code to compile if you're embedding CLIPS in the same manner as the WrappedDLLExample.
The following code demonstrates how to set up a simple print router when using the SimpleLibExample. It surrounds each string of text to be printed within <> so that you can easily see it's being invoked:
#include "clipscpp.h"
using namespace CLIPS;
static char *m_lName = "abc";
class myCLIPSRouter : public CLIPSCPPRouter
{
public:
virtual int Query(CLIPSCPPEnv *,const char *);
virtual int Print(CLIPSCPPEnv *,const char *,const char *);
};
int main()
{
CLIPSCPPEnv theEnv;
myCLIPSRouter theRouter;
theEnv.AddRouter("myRouter",100,&theRouter);
theEnv.Build("(defrule hello"
" =>"
" (printout abc \"Hello World.\" crlf)"
" (printout abc \"Hit return to end.\" crlf)"
" (readline))");
theEnv.Reset();
theEnv.Run(-1);
return 0;
}
int myCLIPSRouter::Query(CLIPSCPPEnv *cEnv,const char *logicalName)
{
int n = strcmp(logicalName,m_lName);
if(strcmp(logicalName,m_lName) == 0)
return 1;
else
return 0;
}
int myCLIPSRouter::Print(CLIPSCPPEnv *cEnv,const char *logicalName,const char *output)
{
printf("<%s>",output);
return 1;
}
The same code can also work with the WrappedDLLExample, but the router APIs need to be exposed in the DLL. There are code updates to do this checked in the SVN repository here: http://sourceforge.net/p/clipsrules/code/HEAD/tree/microsoft_windows/Source/Integration/. You'll need to recompile the DLL and libraries (CLIPSDynamic, CLIPSStatic, and CLIPSWrapper Projects in the CLIPS Solution).