|
Posted by cola on May 13, 2007, 9:39 pm
Please log in for more thread options
refering to helloplug example ,i wrote a weather plugin for homescreen
by vc++ net on windows mobile 5.0 smartphone.and i want to access a .net
component,Weatherlib.dll,based on windows mobile 5.0 smartphone,so i exposed
Weatherlib.dll as a type library,Weatherlib.tlb.
here is the code to access Weatherlib.tlb.
but the method GetInfo() always returns "Com initialize failed",
that is CoInitializeEx fails to initialize com.
does it make,i mean,accessing a type library in my homescreen plugin program.
thanks in advance.
#include "objbase.h"
#import "Weatherlib.tlb"
using namespace Weatherlib;
LPCTSTR GetInfo()
{
HRESULT hr=CoInitializeEx(NULL,COINIT_MULTITHREAD);
LPCTSTR info;
if(hr==S_OK)
{
Weatherlib::_Weather *weather;
Weatherlib::_WeatherPtr p(__uuidof(Weatherlib::Weather));
weather=p;
info=(LPCTSTR)(weather->GetInfo());
weather->Release();
CoUninitialize();
}
else
{
info=L"Com initialize failed";
}
return info;
}
ps:Weatherlib implementation by C#
#region Using directives
using System;
using System.Text;
using System.Runtime.InteropServices;
#endregion
namespace Weatherlib
{
[Guid("D6F88E95-8A27-4ae6-B6DE-0542A0FC7039")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface _Weather
{
[DispId(1)]
string GetInfo();
}
[Guid("13FE32AD-4BF8-495f-AB4D-6C61BD463EA4")]
[ClassInterface(ClassInterfaceType.None)]
public class Weather :_Weather
{
public Weather()
{
}
public string GetInfo()
{
return "Testing ok";
}
}
}
|