Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,811,995 Members 50,216 Now Online
XDA Developers Android and Mobile Development Forum

The DllImport Project (+/also C++ Wrapper) [Mango Support]

Tip us?
 
fiinix
Old
(Last edited by fiinix; 7th November 2011 at 10:09 PM.) Reason: Mango support - Added
#1  
fiinix's Avatar
Retired Recognized Developer - OP
Thanks Meter 224
Posts: 568
Join Date: Oct 2010
Location: Stockholm

 
DONATE TO ME
Arrow The DllImport Project (+/also C++ Wrapper) [Mango Support]

The DllImport Project

This project is part "Real DllImport" and also not the same time. It has limited DllImport to only types "void();" (well isn't that DllImport )

Other CORE functions that require multiple [IN] or/and [OUT] are to complex for the code right now (there are so many possibilities).


Terms of use, using the code (free to use, under my name "fiinix00 @ XDA"~ in app)

As posted to JaxBot
Quote:
Well thanks for asking, this project is free for everyone, the one purpose it was made for.
The only thing i needed back is my name (fiinix @ XDA) included in whose projects (external) that take use of my code base. There is no licence or something (GNU e.g.), it just make people mad and confused.

So feel free to take advantage of the code whenever you want, just remember, i want my name on it. =D


UPDATE @ (2011y-03m-26d - 23:08)

Ohyeah, i can control zune from my application (Resume, Stop, Pause, NextSong, PrevSong, ShutdownZune, StartZune, ... to come)

Turn on/off radio remote from code. (DAMN, the radio begins to play without "No antenna" but no sound, plugin again and it sounds :/)


UPDATE @ (2011-03-27 - 14:35)
- Set clipboard (lol, doesent even have NODO): DllImportCaller.lib.Clipboard_SET("Hello");
- Get clipboard: DllImportCaller.lib.Clipboard_GET(ref [string]);
- Enchanted: Phone.Clipboard.Value { get { ... } set { ... } }
- Basic calls against void without arguments: DllImportCaller.lib.VoidCall( [DLL] , [Method] );
- API for verifying method existence: DllImportCaller.NativeMethodExists( [DLL] , [Method] );
- Raw API for controlling vibrator (unlimited "on", also continues to vibrate on exit, dont forget to turn off ): Phone.Vibrator. { Vibrate(), Stop() }


Source code + test XAP updated (2011-03-27-17:38) (Clipboard GET; is corrupt)

HELLO THERE TASKMANAGER!!
(I can now enumerate the running processes on the phone )
Proof: http://moitox.com/WP7tskMngr.png


Hook to keyboard, for some reason it only show interest in the "Search" button.

Documentation of proc:
[WP7Process].{ CreationTime, ExitTime, KernelTime, UserTime, <-UpdateTimes(), Kill(exitCode), { PROCESSENTRY32 RAW } }

^ for "currentProcess.Kill()" use "Phone.TaskManager.GentlyExitCurrentProcess(); " the Kill(exitCode) KILLS

WP7Process[] = Phone.TaskManager.Named("taskhost");
WP7Process = Phone.TaskManager.CurrentProcess();


Documentation of network
- ConnectionType { Unk0, Unk1, Unk2, Connected, Unk3 ... }
- ConnectionType = Phone.Network.GetWirlessState;



Phone.KeyboardHook.IsKeyDown(int key)
> Search = 124 (lol)


Misc finds

DllImportCaller.NativeMethodExists("urlmon", "IsIntranetAvailable");
DllImportCaller.NativeMethodExists("urlmon", "ObtainUserAgentString");

- Code updated! (2011-03-28-22:12)


Added "Phone.DEP", dep is a wrapper against info stored in "Microsoft.Phone.Info.DeviceExtendedProperties "

Full "TaskHost.exe" support

HostInformation = Phone.TaskHost.GetCurrenHostInfo();

HostInformation {
fDehydrating = 0,
fRehydrated = 0,
hHostWnd = -25821178 /* This silverlight managed window (host window) */
szAppDataFolder = "\\Applications\\Data\\8DC5214E-88FA-4C2D-A379-2CD74FE24B72\\Data"
szAppInstallFolder = "\\Applications\\Install\\8DC5214E-88FA-4C2D-A379-2CD74FE24B72\\Install"
szAppIsolatedStorePath = "\\Applications\\Data\\8DC5214E-88FA-4C2D-A379-2CD74FE24B72\\Data\\IsolatedStore"
szProductId = "{8DC5214E-88FA-4C2D-A379-2CD74FE24B72}"
szTaskPage = "MainPage.xaml" /* Current page? */
szUri = "app://8DC5214E-88FA-4C2D-A379-2CD74FE24B72/_default"
ullLastInstanceId = 39 /* fully retarded property? */
}

Code updated! (2011-03-29-23:25)

new Phone functionality

Phone.OS.{ Shutdown(ewxCode) } /* 1.0.2 can still call it with "DllImportCaller.lib.ShutdownOS" (failed tho on mine in 1.0.2) */

Added "GetLastError7" (C++ ::GetLastError()) for better C# side error handling.

Code updated! (2011-04-03-12:37)


Code updated! (2011-04-04-21:48)
- App launcher code!!
- Enchanted IO support
- 1.0.6!

Code updated! (2011-04-05-22:08)
- Enchanted task support
- Console7.Title { get; set; } etc.


Code updated! (2011-04-08-00:03)
- Stable%: 97 :/
- Battery support (see battery info (CORE only))
- Phone.Sound { MasterVolume!! { get; set; }, etc } (controlling phone master volume over all processes)
- Phone.OS.Kernel.ResetDevice(); (instant stops kernel, instant shutdown, not recommended!)


Code updated! (2011-04-09-22:39)
- Enchanted "Phone.Battery" class
- Phone.TaskManager.+GetCurrentProcessId
- WiFi Controll! (On/Off) (from code!)
- Bluetooth Controll! (On/Off) (from code here toe!)
- Phone.OS.+GetSystemStartupItems(),+GetDesktopWindo wHandle()
- New class "Phone.Search."+SearchFor,+OpenSearch,+BindSearchB uttonToPage (FAILS)
- New class "Phone.XboxLive"+GetIsXboxLiveEnable,+GetIsSignedI n
- Yep: 1.0.9!

Code updated! (2011-04-17-22:01) //damn, not update in 8 days~
- Phone.OS.OSLanguage { SubLanguageID, PrimaryLanguageID }
- Phone.WP7Process.+ CurrentProcessID (int),+GetCurrentProcess() returns guaranteed the right taskhost @class_WP7Process
- Improved Phone.OS.Memory
- + Extra i don't remember (8 days)

Code updated! (2011-05-22-21:25)
- 1.2.1 (because 1.2 methods was commented out to set things right (less crash))
- HUGE improvements
- Removed unneeded **** to speed things up
- Screenshot 161 ms per capture (non-save-to-gallery) =D
- =D

Mango support added(2011-10-26-19:30)
- yep, "ATL" Mango compiled. I have not yet tested to run it on a NoDo.
- Trying to implement a ASM virtual machine; example:
Code:
[ASMMethod(Dll = "coredll", EntryPoint = "GetLastError")]
public delegate int GetLastError();

var last = ASMGenerator.GenerateDelegateFor<GetLastError>();
int code = last();
Custom tile support added(2011-11-07-23:08)
- Custom core tiles ftw!
[/CODE]

Source: Attatchment
-Compile VS2008 folder with C++ compiler from WM6 SDK
-Windows Mobile SDK 6 PRO
-Visual Studio 2010 (+ WP7 Silverlight SDK)

Test-app: Attatchment
-Deploy
-No need anymore to do a initialize button call, automatic called on first use in code "DllImportcaller.lib.cctor" by JIT (Net Framework just in time).
-Do some tests from the scrolling list. (due there are more CORE back-code API's than buttons, all tests can not be tested).


OLDER VERSIONS WILL BE DEPRECATED AND WILL BE REPLACED BY NEWER, MAX ATTACHMENTS IS 8.
Samsung Omnia 7
- ATO MAGLDR v2
Windows Phone 7

The hottest geek girl in the world SassiBoB, SassyBoB, Sassy BoB, sassibob
May the Thanks's button be with me at all time Luke Skywalker
The Following 27 Users Say Thank You to fiinix For This Useful Post: [ Click to Expand ]
 
davux
Old
#2  
Retired Recognized Developer
Thanks Meter 33
Posts: 105
Join Date: Aug 2010
Quote:
Originally Posted by fiinix View Post
Searched for dllimport but did not found what i was searching for; so i need to ask about if it is possible to do a dllimport with interop in meta?
Because if not, i think i have found something quite the same without dllimport.

We can't p/invoke, but only use COM interfaces to interop with native code. What did you find?
 
fiinix
Old
#3  
fiinix's Avatar
Retired Recognized Developer - OP
Thanks Meter 224
Posts: 568
Join Date: Oct 2010
Location: Stockholm

 
DONATE TO ME
Im trying the method, of c++ calling the calls for me.

In c++ i call "HMODULE dll = LoadLibrary("MyDLL.dll");" to get the native kerner32.dll e.g.
Then call "Dword addr = GetProcAddress(dll, "MyMethod");"

Code:
typedef HRESULT (STDAPICALLTYPE * LPFNBOX) (void);

C# -> COM (LoadLibrary e.g.) -> 
return dll addr -> return to C#
C# -> COM -> LPFNBOX * val = (LPFNBOX)GetProcAddress(addr, "method"); -> 
return val(); -> 
return to C#
May work with some privileges bypass, not tested. (^ Not programmer, skip it)
Samsung Omnia 7
- ATO MAGLDR v2
Windows Phone 7

The hottest geek girl in the world SassiBoB, SassyBoB, Sassy BoB, sassibob
May the Thanks's button be with me at all time Luke Skywalker
 
fiinix
Old
#4  
fiinix's Avatar
Retired Recognized Developer - OP
Thanks Meter 224
Posts: 568
Join Date: Oct 2010
Location: Stockholm

 
DONATE TO ME
Step 1 of 2 "LoadLibrary7" S_OK (success!)
Samsung Omnia 7
- ATO MAGLDR v2
Windows Phone 7

The hottest geek girl in the world SassiBoB, SassyBoB, Sassy BoB, sassibob
May the Thanks's button be with me at all time Luke Skywalker
 
fiinix
Old
#5  
fiinix's Avatar
Retired Recognized Developer - OP
Thanks Meter 224
Posts: 568
Join Date: Oct 2010
Location: Stockholm

 
DONATE TO ME
int result;
var hr = lib.MessageBox7("lpText", "lpCaption", MB.MB_OK, out result);

And: It shows a native msg box
Samsung Omnia 7
- ATO MAGLDR v2
Windows Phone 7

The hottest geek girl in the world SassiBoB, SassyBoB, Sassy BoB, sassibob
May the Thanks's button be with me at all time Luke Skywalker
 
fiinix
Old
#6  
fiinix's Avatar
Retired Recognized Developer - OP
Thanks Meter 224
Posts: 568
Join Date: Oct 2010
Location: Stockholm

 
DONATE TO ME
It ** worked!

var t = DllImportCaller.Call<string, string>("coredll.dll", "CeRunAppAtEvent", "emptyArgs");

LoadLibrary7( .. "coredll.dll" .. ) @ -1304248592
GetProcAddress7( .. CeRunAppAtEvent" .. ) @ 1105512120

Now just "box" and call it
Samsung Omnia 7
- ATO MAGLDR v2
Windows Phone 7

The hottest geek girl in the world SassiBoB, SassyBoB, Sassy BoB, sassibob
May the Thanks's button be with me at all time Luke Skywalker
 
kuerbis2
Old
#7  
Member
Thanks Meter 58
Posts: 47
Join Date: Dec 2009
Sounds sweet. Any code to share?
 
fiinix
Old
#8  
fiinix's Avatar
Retired Recognized Developer - OP
Thanks Meter 224
Posts: 568
Join Date: Oct 2010
Location: Stockholm

 
DONATE TO ME
Quote:
Originally Posted by kuerbis2 View Post
Sounds sweet. Any code to share?
Well, last step now is to box it. Due "Compact Framework 3.7" there is no "Marshal.GetDelegateForFunctionPointer". But iw found something quite common.

Code, yes. (if i succeed)
Samsung Omnia 7
- ATO MAGLDR v2
Windows Phone 7

The hottest geek girl in the world SassiBoB, SassyBoB, Sassy BoB, sassibob
May the Thanks's button be with me at all time Luke Skywalker
The Following User Says Thank You to fiinix For This Useful Post: [ Click to Expand ]
 
fiinix
Old
#9  
fiinix's Avatar
Retired Recognized Developer - OP
Thanks Meter 224
Posts: 568
Join Date: Oct 2010
Location: Stockholm

 
DONATE TO ME
Well, there we go. I did just shut down the phone with code (phone sided code)!

DllImportCaller.lib.ShutdownOS();
Samsung Omnia 7
- ATO MAGLDR v2
Windows Phone 7

The hottest geek girl in the world SassiBoB, SassyBoB, Sassy BoB, sassibob
May the Thanks's button be with me at all time Luke Skywalker
The Following 2 Users Say Thank You to fiinix For This Useful Post: [ Click to Expand ]
 
__ow
Old
(Last edited by __ow; 24th March 2011 at 11:37 PM.)
#10  
Member
Thanks Meter 5
Posts: 58
Join Date: Mar 2010
nevermind.

The Following User Says Thank You to __ow For This Useful Post: [ Click to Expand ]
Tags
dllimport, project, wp7
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes