Re: baffled by exception
From: Bonj (Bonj_at_discussions.microsoft.com)
Date: 10/12/04
- Next message: craig: "Question about storing XML in database...."
- Previous message: James Curran: "Re: Inverted enumerator"
- In reply to: Nicholas Paldino [.NET/C# MVP]: "Re: baffled by exception"
- Next in thread: Sigurd Stenersen: "Re: baffled by exception"
- Reply: Sigurd Stenersen: "Re: baffled by exception"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 12 Oct 2004 08:45:04 -0700
> Can you show how you are doing it in
> ..NET and how you are doing it in C++?
(The library is called MyObjX and the object is called MyObj):
in C++:
#include "stdafx.h"
#using <mscorlib.dll>
using namespace System;
using namespace Interop::MyObjX;
using namespace System::Runtime::InteropServices;
[STAThread]
int _tmain()
{
MyObjClass* emb = __gc new MyObjClass();
return 0;
}
//in unmanaged c++ (I first added the myobj.IDL file with the contents of
its type library in COM / object viewer, and then compiled it to produce
myobj_i.c and myobj_h.h
#include <tchar.h>
#include <objbase.h>
#include <comdef.h>
#include "myobj_h.h"
void GetPrediction()
{
HRESULT hr = CoInitialize(NULL);
_MyObj* ip;
try
{
hr = CoCreateInstance(CLSID_MyObj, NULL, CLSCTX_INPROC_SERVER, IID__MyObj,
(void**)&ip);
}
catch(_com_error e)
{
const _TCHAR* s = e.ErrorMessage();
}
CoUninitialize();
}
// in C# (which works):
using System;
using MyObjX;
namespace UseEmbCsharp
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static int Main(string[] args)
{
MyObjX.MyObjClass p = new MyObjClass();
return 0;
}
}
}
> This seems highly unlikely to me, as the mechanism in .NET ultimately
> uses the same mechanism that C++ uses.
That's what I thought. This is why it baffles me.
> Perhaps you are not setting up the
> environment or the apartment correctly, and this could be the source of your
> problems.
I can't see what differences there could be - if you can think of any,
please let me know! I've added the [STAThread] attribute to the main of the
MC++ project just like the C# one, and it still doesn't work. I don't know
how to set this for UMC++ - but I think it's more likely to be a security
thing than a threading thing - as the exception that is thrown completely
ignores try..catch handlers, and the COM object is protected with a dongle.
But it is installed completely correctly and legally, and the dongle is
plugged in, and as I say, it works from all languages but ANY breed of
C++.... it's completely weird......
- Next message: craig: "Question about storing XML in database...."
- Previous message: James Curran: "Re: Inverted enumerator"
- In reply to: Nicholas Paldino [.NET/C# MVP]: "Re: baffled by exception"
- Next in thread: Sigurd Stenersen: "Re: baffled by exception"
- Reply: Sigurd Stenersen: "Re: baffled by exception"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|