Home Help Center

About return struct

slice code:
module HX
{
	
	struct HXMessage
	{
		int messageid;
		string userid;
		string password;
		
	};

      
	struct HXCallMessage
	{
		int messageid;
		string Hintstr;
	};	

	interface HXSocket
	{
		["ami"] HXCallMessage GetLogin(HXMessage Message);
	
	
	};	
};


client code:
#include <Ice/Ice.h>
#include <IceUtil/IceUtil.h>
#include "IceMessages.h"
#include "HX.h"
#include "windows.h"

using namespace std;
using namespace HX;
using namespace IceUtil;



//////////////////////&#20840;&#23616;&#21464;&#37327;&#21306;//////////////
	COnLogin OnLogin=NULL;
//////////////////////&#20840;&#23616;&#21464;&#37327;&#21306;//////////////


class CIceCallback:virtual public HX::AMI_HXSocket_GetLogin
{
public:

	virtual void ice_response( const HXCallMessage& result )
{
cout<<"ok"<<endl;	
  if(OnLogin!=NULL)
  { CIceCallMessage IceCallMessage;
  memcpy(IceCallMessage.Hintstr,result.Hintstr.c_str(),strlen(result.Hintstr.c_str()));
	IceCallMessage.messageid=result.messageid;
  }

	return;
};

virtual void ice_exception(const Ice::Exception&)
{
return;
};

};



class IceClient
{
private:
	Ice::CommunicatorPtr ic;
	struct Ice::InitializationData initdata;
	HXSocketPrx SocketClient;
	AMI_HXSocket_GetLoginPtr IceCallback; 
	struct HXMessage HXMsg;
	public:
	IceClient()
	{
	};
	IceClient(char *config);

	int send(CIceMessage IceMessage);

    ~IceClient()
	{
	
		if(ic)
	{
	ic->shutdown();
	ic->destroy();
	}
	};
};

IceClient::IceClient(char *config)
{
	Ice::PropertiesPtr props;
	props=Ice::createProperties();
	props->load(config);
	initdata.properties=props;
	ic=Ice::initialize(initdata);
	
	Ice::ObjectPrx base=ic->stringToProxy("HX:default -p 10000");
	SocketClient=HXSocketPrx::checkedCast(base);
	if(!SocketClient)
			throw "Invalid proxy";

	IceCallback=new CIceCallback;
	
};

int IceClient::send(CIceMessage IceMessage)
{
	switch(IceMessage.messageid)
	{
	case HX_LOGIN:{
						HXMsg.userid.append(IceMessage.userid,strlen(IceMessage.userid));//&#20801;&#35768;&#29992;&#25143;&#36755;&#20837;14&#20301;
						HXMsg.password.append(IceMessage.password,strlen(IceMessage.password));//&#20801;&#35768;&#29992;&#25143;&#36755;&#20837;14&#20301;
						SocketClient->GetLogin_async(IceCallback,HXMsg);
						break;
				  }

	};
	
		return 1;

};


////////////////////////////&#20840;&#23616;&#21306;&#22495;////////////////////////////////////
IceClient *Client;

int _stdcall loadice(char *config)
{
		Client=new IceClient(config);
	
return 1;
	
};



void _stdcall unloadice()
{

	if(Client!=NULL) delete Client;
};

int _stdcall sendmessage(CIceMessage IceMessage)
{
	int result;
	if(Client!=NULL) result=Client->send(IceMessage);
	return result;
};

int main()
{
loadice("Config.cfg");
CIceMessage IceMessage;
IceMessage.callback=NULL;
IceMessage.messageid=HX_LOGIN;
IceMessage.userid="AAA";
IceMessage.password="fff";

sendmessage(IceMessage);
delete Client;

};
////////////////////////////&#20840;&#23616;&#21306;&#22495;////////////////////////////////////

Comments

  • Serve Code:
    // **********************************************************************
    //
    // Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
    //
    // This copy of Ice is licensed to you under the terms described in the
    // ICE_LICENSE file included in this distribution.
    //
    // **********************************************************************
    
    #include <Ice/Ice.h>
    #include "HX.h"
    #include "IceMessages.h"
    
    using namespace std;
    using namespace HX;
    
    class SocketServer : virtual public HXSocket {
    public:
         virtual ::HX::HXCallMessage GetLogin(const ::HX::HXMessage& HXMsg, const ::Ice::Current&)
    	{ struct HXCallMessage CallbackMessage;
    		cout<<"=>>=>>=>>=>>=>>=>>=>>=>>=>>=>>"<<endl;
    		cout<<"&#30331;&#38470;&#29992;&#25143;&#65306;"<<HXMsg.userid<<endl;
    		cout<<"&#30331;&#38470;&#23494;&#30721;&#65306;"<<HXMsg.password<<endl;
    		cout<<"=>>=>>=>>=>>=>>=>>=>>=>>=>>=>>"<<endl;
    		CallbackMessage.messageid=HX_RETURN_LOGIN;
    		CallbackMessage.Hintstr="&#21040;&#20102;&#21313;&#32423;&#20351;&#29992;&#31069;&#31119;&#23453;&#30707;&#65292;&#21487;&#20197;&#33719;&#24471;&#21452;&#20493;&#32463;&#39564;";
    		cout<<CallbackMessage.messageid<<"::"<<CallbackMessage.Hintstr<<endl;
    		return CallbackMessage;
    	};
    };
    
    
    int
    main(int argc, char* argv[])
    {
        int status = 0;
        Ice::CommunicatorPtr ic;
        try {
    	ic = Ice::initialize(argc, argv);
    	Ice::ObjectAdapterPtr adapter
    	    = ic->createObjectAdapterWithEndpoints(
    		"HX", "default -p 10000");
    	Ice::ObjectPtr object = new SocketServer;
    	adapter->add(object,
    		     ic->stringToIdentity("HX"));
    	adapter->activate();
    	ic->waitForShutdown();
        } catch (const Ice::Exception & e) {
    	cerr << e << endl;
    	status = 1;
        } catch (const char * msg) {
    	cerr << msg << endl;
    	status = 1;
        }
        if (ic) {
            try {
    	    ic->destroy();
    	} catch (const Ice::Exception & e) {
    	    cerr << e << endl;
    	    status = 1;
    	}
        }
        return status;
    }
    
    
    When I runs,ice_response can't be called.
  • runs exception:

    [ Network: trying to establish tcp connection to 192.168.0.34:10000 ]
    [ Network: tcp connection established
    local address = 192.168.0.34:4876
    remote address = 192.168.0.34:10000 ]
    [ Network: received 14 of 14 bytes via tcp
    local address = 192.168.0.34:4876
    remote address = 192.168.0.34:10000 ]
    [ Protocol: received validate connection
    message type = 3 (validate connection)
    compression status = 0 (not compressed; do not compress response, if any)
    message size = 14 ]
    [ Protocol: sending request
    message type = 0 (request)
    compression status = 0 (not compressed; do not compress response, if any)
    message size = 54
    request id = 1
    identity = HX
    facet =
    operation = ice_isA
    mode = 1 (nonmutating)
    context = ]
    [ Network: received 14 of 14 bytes via tcp
    local address = 192.168.0.34:4876
    remote address = 192.168.0.34:10000 ]
    [ Network: sent 54 of 54 bytes via tcp
    local address = 192.168.0.34:4876
    remote address = 192.168.0.34:10000 ]
    [ Network: received 12 of 12 bytes via tcp
    local address = 192.168.0.34:4876
    remote address = 192.168.0.34:10000 ]
    [ Protocol: received reply
    message type = 2 (reply)
    compression status = 0 (not compressed; do not compress response, if any)
    message size = 26
    request id = 1
    reply status = 0 (ok) ]
    [ Protocol: sending asynchronous request
    message type = 0 (request)
    compression status = 0 (not compressed; do not compress response, if any)
    message size = 52
    request id = 2
    identity = HX
    facet =
    operation = GetLogin
    mode = 0 (normal)
    context = ]
    [ Network: sent 52 of 52 bytes via tcp
    local address = 192.168.0.34:4876
    remote address = 192.168.0.34:10000 ]
    [ Protocol: sending close connection
    message type = 4 (close connection)
    compression status = 1 (not compressed; compress response, if any)
    message size = 14 ]
    [ Network: sent 14 of 14 bytes via tcp
    local address = 192.168.0.34:4876
    remote address = 192.168.0.34:10000 ]
    [ Network: received 14 of 14 bytes via tcp
    local address = 192.168.0.34:4876
    remote address = 192.168.0.34:10000 ]
    [ Network: received 54 of 54 bytes via tcp
    local address = 192.168.0.34:4876
    remote address = 192.168.0.34:10000 ]
    [ Protocol: received reply
    message type = 2 (reply)
    compression status = 0 (not compressed; do not compress response, if any)
    message size = 68
    request id = 2
    reply status = 0 (ok) ]
    [ Network: shutting down tcp connection for writing
    local address = 192.168.0.34:4876
    remote address = 192.168.0.34:10000 ]
    warning: unknown exception raised by AMI callback
    [ Network: closing tcp connection
    local address = 192.168.0.34:4876
    remote address = 192.168.0.34:10000 ]
    Press any key to continue
  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    The warning indicates that a non-Ice exception is raised by your code in ice_response(). I don't know why, because I don't know the code for CIceCallMessage, but I suspect it is some kind of memory management error, which causes a Microsoft exception to be raised. Remove the memcpy() and check if you still get an exception.
  • My struct define:
    struct CIceMessage
    {
    	int messageid;
    	char *userid;
    	char *password;
    	void *callback;
    };
    
    struct CIceCallMessage
    {
    	int messageid;
     char *Hintstr;
    };
    const HX_LOGIN=0;
    const HX_ICE_CALLBACK=1;
    const HX_RETURN_LOGIN=2;
    

    Now I change the "ice_response" code
    	virtual void ice_response( const HXCallMessage& result )
    {
    cout<<"ok"<<endl;
    };
    

    the exception messages still exist.
  • matthewmatthew NL, CanadaMember Matthew NewhookOrganization: ZeroC, Inc.Project: Internet Communications Engine ✭✭✭
    Posting small snippets of code like this isn't really helpful. There isn't enough information for us to diagnose your problem. All this snippet of code tells me is that there was some previous memory error in your application -- perhaps you allocated the AMI callback on the stack or something similar. I recommend tracing through the issue with a debugger.

    If you want further assistance with this problem you should package up a complete, small, compilable example that demonstrates the issue and we'd be happy to look further.
  • this is all of my code.
    Thanks.
  • matthewmatthew NL, CanadaMember Matthew NewhookOrganization: ZeroC, Inc.Project: Internet Communications Engine ✭✭✭
    You are linking with "stlport_vc6.lib stlport_vc6_stldebug.lib". You should not do this. These libraries are linked automatically by the compiler. In addition, you must enable RTTI when compiling. In addition the call to waitForShutdown in the client is unecessary because there is no server side to shutdown.
Sign In or Register to comment.