how to create a VB/C# CF helper dll

R

Robert Regnell

Hi,

I program in eVB 3.0 and Pocket PowerBuilder for WinCE devices. I started
looking into the CF using VB/C# recently in order to create some a DLL that
does some simple things like memory available, battery status, get handheld
name, uniques ID, ...

I have found many example of how to implement these APIs and have a working
VB.net executable. What I would like to do is create a class library (DLL)
that would expose these methods to another application. My problem is I
don't think I'm doing it properly.

I have created a VB.net Class library project, (see below) which compiles
fine, and I have created public functions for a couple methods I want
exposed.

Ideally, I would like to access these methods like a standard API call. I
would declare the function as coming from this DLL I wrote with a return of
a particalur type.

Can this be done? I couldn't find any information on how to explicitly
expose the methods other than making their definitions Public. The DLL does
not appear to get registered in HKCR to expose the class "Support".

Any help would be greatly appreciated.

Thanks, Bob



Public Class Support
<System.Runtime.InteropServices.DllImport("coredll.dll", _
SetLastError:=False)> _
Public Shared Sub GlobalMemoryStatus(ByRef ms As MEMORY_STATUS)
End Sub

<System.Runtime.InteropServices.DllImport("coredll.dll", _
SetLastError:=False)> _
Public Shared Function GetSystemPowerStatusEx(ByRef lpSystemPowerStatus
As SYSTEM_POWER_STATUS) As Int32
End Function

Public Function Get_Battery_Percent_Remaining() As Int16
Dim p As New SYSTEM_POWER_STATUS

GetSystemPowerStatusEx(p)
Return CInt(p.BatteryPercent)
End Function

Public Function Get_Memory_Total() As String
Dim p As New MEMORY_STATUS

GlobalMemoryStatus(p)
Return p.dwTotalPhys.ToString()
End Function

Public Function Get_Memory_Available() As String
Dim p As New MEMORY_STATUS

GlobalMemoryStatus(p)
Return p.dwAvailPhys.ToString()
End Function

Public Structure SYSTEM_POWER_STATUS
Public ACLineStatus As Byte
Public BatteryFlag As Byte
Public BatteryPercent As Byte
Public Reserved1 As Byte
Public BatteryLifeTime As Int32
Public BatteryFullTime As Int32
Public Reserved2 As Byte
Public BackupBatteryFlag As Byte
Public BackupBatteryPercent As Byte
Public Reserved3 As Byte
Public BackupBatteryLifeTime As Int32
Public BackupBatteryFullTime As Int32
End Structure

Public Structure MEMORY_STATUS
Public dwLength As UInt32
Public dwMemoryLoad As UInt32
Public dwTotalPhys As UInt32
Public dwAvailPhys As UInt32
Public dwTotalPageFile As UInt32
Public dwAvailPageFile As UInt32
Public dwTotalVirtual As UInt32
Public dwAvailVirtual As UInt32
End Structure
End Class
 
C

Chris Tacke, eMVP

There is no provision in v 1.0 of the CF for hosting the EE. THis means
it's just not possible to call into managed code from unmanaged code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top