开发者

smartdevice C# dll in VC++ using Windows Mobile

I'm trying to create a DLL in C# for Windows Mobile and I have an error when I try to access the DLL in VC++.

Is it possible to create a DLL in C# and access it in VC++ using Windows Mobile?

I'm using Windows Mobile 6 SDK.

The following code works very well on Desktop.

C# code:

using System; 
using System.Collections.Generic; 
using System.Text; 
using System.Runtime.InteropServices; 
namespace HttpLibrary 
{ 
    [ComVisible(true)] 
    [StructLayout(LayoutKind.Sequential)] 
    public struct StorageGroup 
    { 
        public int count; 
        public string[] Name; 
        public string[] sgdName; 
        public string[] logfolder; 
        public string[] systemfolder; 
    } 
    [ComVisible(true)] 
    public struct MyResult 
    { 
        public string Name; 
    } 
    [ComVisible(true)] 
    [Guid("F55EDB71-E3FC-4FC2-A25B-6E09C49B3E93")] 
    public interface IMyClass1 
    { 
        int helloWorld(); 
        StorageGroup getStorageGroup(); 
    } 
    [ClassInterface(ClassInterfaceType.None)] 
    [Guid("7B0D798D-DD45-41E1-A0D4-2FC453B36CED")] 
    [ComVisible(true)] 
    public class Class1 : IMyClass1 
    { 
        public Class1() 
        { 
            //constructor.. create object.. 
        } 
        public int helloWorld() 
        { 
            //don't do anything just return 10 so that client can ge开发者_如何学Got the return value.. 
            return 10; 
        } 
        public MyResult helloWorld(int i) 
        { 
            MyResult result = new MyResult(); 
            result.Name = "jigar"; 
            return result; 
        } 
        public StorageGroup getStorageGroup() 
        { 
            //Put code here.. 
            StorageGroup sg = new StorageGroup(); 
            int count = 3; 
            sg.Name = new string[count]; 
            sg.sgdName = new string[count]; 
            sg.logfolder = new string[count]; 
            sg.systemfolder = new string[count]; 
            sg.count = count; 
            for (int i = 0; i < count; i++) 
            { 
                sg.Name[i] = (i * 100).ToString(); 
                sg.sgdName[i] = i.ToString(); 
                sg.logfolder[i] = i.ToString(); 
                sg.systemfolder[i] = i.ToString(); 
            } 
            return sg; 
        } 
    } 
} 

C++ code:

#import "c:\\pocket\\HTTP_POST_CS\\HttpLibrary\\HttpLibrary\\bin\\Debug 
\\HttpLibrary.tlb" 
BOOL CHttpLibraryTestDlg::OnInitDialog() 
{ 
        CDialog::OnInitDialog(); 
        // Set the icon for this dialog.  The framework does this 
automatically 
        //  when the application's main window is not a dialog 
        SetIcon(m_hIcon, TRUE);                 // Set big icon 
        SetIcon(m_hIcon, FALSE);                // Set small icon 
        CoInitializeEx(NULL, 0); 
        HttpLibrary::IMyClass1Ptr pIMyClass1(__uuidof(HttpLibrary::Class1)); 
//--->This line gives me a Raise Exception 
        int i=-1; 
        i = (int)pIMyClass1->helloWorld(); 
        return TRUE;  // return TRUE  unless you set the focus to a control 
}


You cannot do this in the Compact Framework because it is missing CLR hosting capabilities. There is no way for a native app to spin up the execution engine inside it's own process, so it can't load managed code. This means your own native apps can't load managed DLLs, nor can the device browser.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜