Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / October 2004

Tip: Looking for answers? Try searching our database.

Changing an unmanaged string from managed code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Roy Chastain - 25 Oct 2004 19:47 GMT
I have successfully loaded a MANAGED C++ dll from an UNmanaged C++ program.  I can even manage to call methods in classes in that
DLL.  What I need to know is how to pass a string back to the UNmanaged code from the managed code.

public __gc __interface KMS::Transport::Managed::IManager
{
    public:
        virtual int Initialize (HRESULT *result, [System::Runtime::InteropServices::Out] String *error_text) = 0;
};

public __gc class KMS::Transport::Managed::Manager: public IManager
{
   
    public:
    Manager (void)
    {
    }
   
    int Initialize (HRESULT *result, [System::Runtime::InteropServices::Out] String *error_text)
    {
        *result = S_OK;
        // how do I set the value of error_text here
    }
}
-------------------------------------------
Roy Chastain
KMSystems, Inc.
Roy Chastain - 26 Oct 2004 17:28 GMT
Well, I found something that appears to work.
Change the signature of the Initialize method to use .... String **error_text instead of String *error_text
Then *error_text = new String("Hello");

The unmanaged code looks like
        int                        ret_val
        BSTR                    msg = _bstr_t(LPVOID(NULL));
        HRESULT            result1;
        result = manager->Initialize(&result1,&msg,&ret_val);
        wprintf(LPWSTR(msg));
        SysFreeString(msg);

>I have successfully loaded a MANAGED C++ dll from an UNmanaged C++ program.  I can even manage to call methods in classes in that
>DLL.  What I need to know is how to pass a string back to the UNmanaged code from the managed code.
[quoted text clipped - 22 lines]
>Roy Chastain
>KMSystems, Inc.

-------------------------------------------
Roy Chastain
KMSystems, Inc.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.