Jessie Wang
Jessie Wang

Reputation: 27

I have integrated CLIPS with VC++(MFC), why there are some function does't execute,such as "strcmp"

I used the CLIPS6.30 version, and the way that I embeded the CLIPS into VC++ was just like the wrappedDLLExample shown in "advance.doc" (using CLIPSWind32.lib and CLIPSWin32CPP.lib).

When I write a class myCLIPSCPPRouter, I need to compare the logicalNames.But the function "strcmp" doesn't work. The code line was skipped.

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

The line (1) will always be shipped. And no matter these two strings (logicalName and m_lName)are the same or not, it goes to the end of the function, ie.the "strcmp()" isn't executed. So wierd*!(I wrote "it goes to 'return FALSE' formerly.it was wrong.")* And there is no error with these two strings. I have changed the both to "abc", and doesn't make a difference.

I have tried other method,like transforming the char* to CString, and then invoking str.compareNoCase().But it's skipped too.

I think maybe the way that I use the CLIPSRouter is wrong. I just want to make the message that CLIPS "printout" can be displayed on the editbox of a Dialog.If you are familliar with CLIPS integration, please tell me the right way. Thank you very very very much!!!!

Upvotes: 2

Views: 410

Answers (1)

Gary Riley
Gary Riley

Reputation: 10757

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).

Upvotes: 1

Related Questions