smartdevice C#DLL在VC ++中
我试图在C#中为Windows Mobile创建一个DLL,并且当我尝试访问VC ++中的DLL时出现错误。 有可能在C#中创建一个DLL并使用Windows Mobile在VC ++中访问它? 我正在使用Windows Mobile 6 SDK。 以下代码在桌面上运行得非常好。
C#代码:
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()
{
//dont do anything just return 10 so that client can get
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
The C++ code:
#import "c:pocketHTTP_POST_CSHttpLibraryHttpLibrarybinDebug
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
}
您不能在Compact Framework中执行此操作,因为它缺少CLR托管功能。 本机应用程序无法在自己的进程中启动执行引擎,因此无法加载托管代码。 这意味着您自己的本机应用程序无法加载受管DLL,设备浏览器也无法加载。
链接地址: http://www.djcxy.com/p/81307.html上一篇: smartdevice C# dll in VC++
下一篇: How to dispose of a NET COM interop object on Release()
