开发者

How to get a return value from unmanaged code via COM Automation in Silverlight?

开发者 https://www.devze.com 2023-02-05 18:19 出处:网络
I am currently trying to invoke some unmanaged code from a Silverlight 4 Out-Of-browser application with elevated privileges.

I am currently trying to invoke some unmanaged code from a Silverlight 4 Out-Of-browser application with elevated privileges.

My simple test code fails with an ArgumentException.

try
{
    dynamic watch = AutomationFactory.CreateObject("WatchCOMLib.HighPerformanceWatch");                

    // Displays ...AutomationMetaObjectProvider
    MessageBox.Show(watch.ToString());  


    // Fails with ArgumentException: Could not convert an argument for the call to GetTimestamp
    ulong tsc;
    watch.GetTimestamp(out tsc);  

    MessageBox.Sh开发者_JS百科ow(tsc.ToString());
}
catch (Exception ex) { MessageBox.Show(ex.ToString()); }

I have created the COM library by using the Visual Studio 2010 ATL Template Wizard; the method looks like

STDMETHODIMP CHighPerformanceWatch::GetTimestamp(ULONGLONG* tsc)
{
    // ....
    *tsc = result; // result is unsigned __int64
    return S_OK;
}

When I simply pass tsc into GetTimestamp without specifying the out keyword, no exception is thrown, but tsc is unchanged. Now... how can I get a value back from the unmanaged library?

Now, there may be plenty of information missing. I've followed a few Hello-World tutorials for creating this COM library, but I don't really have a clue whats goig on there. =) Please ask for anything you need!


Have you checked that the IDL definition of GetTimestamp has the [out] attribute attached to the parameter?

0

精彩评论

暂无评论...
验证码 换一张
取 消