Hello.
Backgrounder first. I'm a VB programmer who's trying out ICE with VB so that I can integrate it with our applications. You can categorize me as a newbie with regards to C++. Also, this post is in connection with
Using ICE with Single Threaded DLL post.
Ok, now with the problem:
1.) I created a VB ActiveX DLL which only has one interface. A function wich accepts a string and returns a string. Pretty simple.
2.) I made the following slice definition to support the DLL.
Quote:
interface jSockets
{
string jclCommand(string command);
};
|
3.) I then proceeded to make a client and a server classes to manage the connection. Here is a code snippit on the server:
jSocketsI.h
Quote:
#include <jSockets.h>
#include <IceUtil/Mutex.h>
#define INITGUID
#import "..\jIceServer\bin\jIceServer.dll"
#include "icrsint.h"
using namespace jIceServer;
class jSocketsI : public jSockets {
public:
virtual ::std::string jclCommand(const ::std::string& command, const Ice::Current&);
jSocketsI();
~jSocketsI();
private:
bool initialize();
_jServerPtr pjServer;
IceUtil::Mutex _jServerMutex;
};
|
jSockets.cpp
Quote:
#include "stdafx.h"
#include "jSocketsI.h"
using namespace std;
std::string jSocketsI::jclCommand(const ::std::string& command, const Ice::Current&) {
// Make sure that were thread safe
IceUtil::Mutex::Lock lock(_jServerMutex);
// Declare used variables
std::string retval;
_bstr_t data = command.c_str();
// Call the J Object and get the return parameter
retval = pjServer->jclCommand(data);
// Return the values
return retval;
}
bool jSocketsI::initialize() {
// Make sure that were thread safe
IceUtil::Mutex::Lock lock(_jServerMutex);
// Make sure that were connected
CoInitialize(NULL);
pjServer.CreateInstance(__uuidof(jServer));
// Return that all is well
return true;
}
jSocketsI::jSocketsI() {
// Initialize the COM environment, this
// extra call ensures that the Adapter Class will
// not go out of scope.
initialize();
}
jSocketsI::~jSocketsI() {
CoUninitialize();
|
Just for completeness, here's the code for the main application
IceServer.cpp
Quote:
#include <Ice/Ice.h>
#include <jSocketsI.h>
using namespace std;
class IceServer : virtual public Ice::Application {
public:
virtual int run(int, char* []) {
// Server code
Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapterWithEndpoints("jclCommandAdapt er", "default -p 7012");
Ice::ObjectPtr object = new jSocketsI;
adapter->add(object, Ice::stringToIdentity("jclCommand"));
adapter->activate();
// Wait until all operations are completed
communicator()->waitForShutdown();
if (interrupted()) {
cerr << appName() << ": received signal, shutting down" << endl;
}
return 0;
};
};
int main(int argc, char* argv[]) {
IceServer app;
return app.main(argc,argv);
}
|
This code will actually compile and run but the problem is that when the clients connects and actually calls the "
jclCommand", it will fail with an access violation in the code:
Quote:
// Call the J Object and get the return parameter
retval = pjServer->jclCommand(data);
|
I don't know what to do anymore. I'm close to just giving up and walking away.
Any help?
Thanks.
Alex