我已经将CLIPS与VC++(MFC)集成在一起,为什么有些函数无法执行,例如"strcmp"



我使用的是CLIPS6.30版本,我将CLIPS嵌入vc++的方式就像"advanced .doc"中所示的wrappedDLLExample(使用CLIPSWind32)。

当我写一个类myclipscpproouter时,我需要比较logicalNames。但是函数"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()"。所以奇怪啊!(我以前写过"it goes to‘return FALSE’"。这是错误的。这两个字符串没有错误。我把两个都改成了"abc",没有什么区别。

我尝试过其他方法,比如将char*转换为CString,然后调用str.compareNoCase(),但是它也被跳过了。

我想也许我使用CLIPSRouter的方式是错误的。我只是想在对话框的编辑框中显示CLIPS的"打印输出"。如果你熟悉CLIPS集成,请告诉我正确的方法。非常非常感谢!!!!

看起来您使用的是CLIPS 6.30的测试版,而不是发布版(来自http://sourceforge.net/projects/clipsrules/files/CLIPS/6.30/的clips_windows_projects_630.zip)。DLL不公开路由器功能,因此如果您以与WrappedDLLExample相同的方式嵌入CLIPS,则不清楚如何使代码编译。

下面的代码演示如何在使用simplelibeexample时设置一个简单的打印路由器。它包围了<>中要打印的每个文本字符串,以便您可以很容易地看到它正在被调用:

#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;
}

相同的代码也可以与WrappedDLLExample一起工作,但是路由器api需要在DLL中公开。在SVN存储库中有相应的代码更新:http://sourceforge.net/p/clipsrules/code/HEAD/tree/microsoft_windows/Source/Integration/。您需要重新编译DLL和库(CLIPS解决方案中的CLIPSDynamic、CLIPSStatic和CLIPSWrapper项目)。

最新更新