![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi I have a C# DLL which has a method which accepts a string argument. This is registered for COM. The resulting .tlb is then referenced in a native C++ DLL. I then wrap the method in a C++ method and add some trace code. The wrapped C# method also includes some trace code. When I attempt to run the C++ method, passing a BSTR to it, the C++ methods trace code fires, however, the C# method call doesn't appear to do anything. Does anything mean that the call succeeds though the trace code is not |
|
The strange thing is that if I remove the string argument from the C# method, regenerate the .tlb and change the wrapper method accordingly the C# trace code fires. I have other methods which accept and return numeric types which issue, it's just this one which accepts a BSTR that seems to be a problem. I should say that the C++ dll has to be native to integrate with an ancient PowerBuilder component which can't be changed, hence the C++ to COM to C# process. Can you please post the affected code of both the C# and the C++ side? |
#3
| |||
| |||
|
|
GlennAnthonyB wrote: Hi I have a C# DLL which has a method which accepts a string argument. This is registered for COM. The resulting .tlb is then referenced in a native C++ DLL. I then wrap the method in a C++ method and add some trace code. The wrapped C# method also includes some trace code. When I attempt to run the C++ method, passing a BSTR to it, the C++ methods trace code fires, however, the C# method call doesn't appear to do anything. Does anything mean that the call succeeds though the trace code is not executed or does it hang? |
|
The strange thing is that if I remove the string argument from the C# method, regenerate the .tlb and change the wrapper method accordingly the C# trace code fires. I have other methods which accept and return numeric types which issue, it's just this one which accepts a BSTR that seems to be a problem. I should say that the C++ dll has to be native to integrate with an ancient PowerBuilder component which can't be changed, hence the C++ to COM to C# process. Can you please post the affected code of both the C# and the C++ side? |
|
--Johannes -- Johannes Passing - http://int3.de/ |
#4
| |||
| |||
|
|
"Johannes Passing" <jpassing_at_hotmail_com (AT) nospam (DOT) com> wrote in message news:O4Vzu7Z4HHA.5880 (AT) TK2MSFTNGP03 (DOT) phx.gbl... GlennAnthonyB wrote: Hi I have a C# DLL which has a method which accepts a string argument. This is registered for COM. The resulting .tlb is then referenced in a native C++ DLL. I then wrap the method in a C++ method and add some trace code. The wrapped C# method also includes some trace code. When I attempt to run the C++ method, passing a BSTR to it, the C++ methods trace code fires, however, the C# method call doesn't appear to do anything. Does anything mean that the call succeeds though the trace code is not executed or does it hang? It's doesn't hang, it just doesn't appear to enter the C# method. The strange thing is that if I remove the string argument from the C# method, regenerate the .tlb and change the wrapper method accordingly the C# trace code fires. I have other methods which accept and return numeric types which issue, it's just this one which accepts a BSTR that seems to be a problem. I should say that the C++ dll has to be native to integrate with an ancient PowerBuilder component which can't be changed, hence the C++ to COM to C# process. Can you please post the affected code of both the C# and the C++ side? C# code fragment... public int Search( string searchString ) { Trace.TraceInformation( "Managed Search method invoked..." ); int status = -1; return status; } C++ code fragment... #include "stdafx.h" #import "Test.tlb" raw_interfaces_only BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { CoInitialize( NULL ); return TRUE; } int Search( BSTR searchString ) { long lResult = 0; Test::ISearchEnginePtr searchEngine( __uuidof( Test::SearchEngine ) ); searchEngine->Search( searchString, &lResult ); printf( "result %d", lResult ); return lResult; } --Johannes -- Johannes Passing - http://int3.de/ Thanks Glenn |
#5
| |||
| |||
|
| "glennanthonyb" <glenn.csharp (AT) yahoo (DOT) co.uk> wrote in message news:eBWg9Iw4HHA.5160 (AT) TK2MSFTNGP05 (DOT) phx.gbl... "Johannes Passing" <jpassing_at_hotmail_com (AT) nospam (DOT) com> wrote in message news:O4Vzu7Z4HHA.5880 (AT) TK2MSFTNGP03 (DOT) phx.gbl... GlennAnthonyB wrote: Hi I have a C# DLL which has a method which accepts a string argument. This is registered for COM. The resulting .tlb is then referenced in a native C++ DLL. I then wrap the method in a C++ method and add some trace code. The wrapped C# method also includes some trace code. When I attempt to run the C++ method, passing a BSTR to it, the C++ methods trace code fires, however, the C# method call doesn't appear to do anything. Does anything mean that the call succeeds though the trace code is not executed or does it hang? It's doesn't hang, it just doesn't appear to enter the C# method. The strange thing is that if I remove the string argument from the C# method, regenerate the .tlb and change the wrapper method accordingly the C# trace code fires. I have other methods which accept and return numeric types which issue, it's just this one which accepts a BSTR that seems to be a problem. I should say that the C++ dll has to be native to integrate with an ancient PowerBuilder component which can't be changed, hence the C++ to COM to C# process. Can you please post the affected code of both the C# and the C++ side? C# code fragment... public int Search( string searchString ) { Trace.TraceInformation( "Managed Search method invoked..." ); int status = -1; return status; } C++ code fragment... #include "stdafx.h" #import "Test.tlb" raw_interfaces_only BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { CoInitialize( NULL ); return TRUE; } int Search( BSTR searchString ) { long lResult = 0; Test::ISearchEnginePtr searchEngine( __uuidof( Test::SearchEngine ) ); searchEngine->Search( searchString, &lResult ); printf( "result %d", lResult ); return lResult; } --Johannes -- Johannes Passing - http://int3.de/ Thanks Glenn |
#6
| |||
| |||
|
|
Hi Glenn, first, there are some issues with your DllMain. DllMain is not only called on initialization but also on termination of process/threads, so you definitely need to switch on ul_reason_for_call rather than always perform the same action. Furthermore, you should never call CoInitialize from DllMain - see [1] for details. Depending on the calling application, this might even be the reason for your problem, so try to fix this first. To use COM in a DLL, create a helper thread (in the C++ Search function) and perform all COM-related work on this thread. [1] http://download.microsoft.com/download/a/f/7/ af7777e5-7dcd-4800-8a0a-b18336565f5b/DLL_bestprac.doc --Johannes "glennanthonyb" <glenn.csharp (AT) yahoo (DOT) co.uk> wrote in message news:eBWg9Iw4HHA.5160 (AT) TK2MSFTNGP05 (DOT) phx.gbl... "Johannes Passing" <jpassing_at_hotmail_com (AT) nospam (DOT) com> wrote in message news:O4Vzu7Z4HHA.5880 (AT) TK2MSFTNGP03 (DOT) phx.gbl... GlennAnthonyB wrote: Hi I have a C# DLL which has a method which accepts a string argument. This is registered for COM. The resulting .tlb is then referenced in a native C++ DLL. I then wrap the method in a C++ method and add some trace code. The wrapped C# method also includes some trace code. When I attempt to run the C++ method, passing a BSTR to it, the C++ methods trace code fires, however, the C# method call doesn't appear to do anything. Does anything mean that the call succeeds though the trace code is not executed or does it hang? It's doesn't hang, it just doesn't appear to enter the C# method. The strange thing is that if I remove the string argument from the C# method, regenerate the .tlb and change the wrapper method accordingly the C# trace code fires. I have other methods which accept and return numeric types which issue, it's just this one which accepts a BSTR that seems to be a problem. I should say that the C++ dll has to be native to integrate with an ancient PowerBuilder component which can't be changed, hence the C++ to COM to C# process. Can you please post the affected code of both the C# and the C++ side? C# code fragment... public int Search( string searchString ) { Trace.TraceInformation( "Managed Search method invoked..." ); int status = -1; return status; } C++ code fragment... #include "stdafx.h" #import "Test.tlb" raw_interfaces_only BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { CoInitialize( NULL ); return TRUE; } int Search( BSTR searchString ) { long lResult = 0; Test::ISearchEnginePtr searchEngine( __uuidof( Test::SearchEngine ) ); searchEngine->Search( searchString, &lResult ); printf( "result %d", lResult ); return lResult; } --Johannes -- Johannes Passing - http://int3.de/ Thanks Glenn -- Johannes Passing - http://int3.de/ |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |