Skip to main content

What is the Current Directory in Windows CE & Windows Mobile ?

Lately i encountered  a situation where i had to find the current directory from where my application is running and all my config files reside. Question is "How do I find the current directory?" on Windows CE/Mobile devices. Desktop / PC it is just piece of cake but Windows CE / Mobile devices don't have a concept of a current directory.  Which means all pats are absolute and there is no concept called relative path. Due to lack of relative paths most of the files are loaded to the "Windows" directory and that is how Windows directory is crowded. Alternatively you can hard code directory path and insist user to load files always there. But i hate to hard code values or copy files to Windows directory. 
So this has triggered to find a solution to identify my current directory. Since there is no concept of a current directory on a Windows CE / Windows Mobile device how would one locate a resource for which only a relative path is known?  That is what following code does 
Code snippet to Find current directory:
===============================
  
   WCHAR* wszTemp = NULL;
   WCHAR  wszDirectory[MAX_PATH] = L"\0";
 
   GetModuleFileNameW(NULL,wszDirectory,MAX_PATH);
 
   wszTemp = wcsrchr(wszDirectory,L'\\'); // Finds last occurence and replace it with NULL.
 
   *(wszTemp+1) = L'\0';

=====================================

Let me explain how does it work: 
GetModuleFileNameW API Retrieves the fully-qualified path for the file that contains the specified module. For example if you are running your applciation from \Application\MyOwn\Sample.exe location then GetModuleFileNameW API retrieves full path and stores in wszDirectory variable. 

wszTemp = wcsrchr(wszDirectory,L'\\');  this step finds last occurrence of "\"   and  replace last occurrence with NULL
Now wszDirectory content would be \Application\MyOwn\   
-------------------------------------------------------------- 

Hope this helps !!! Do let me know if you need any help !!!!!!!!!

Comments

Anonymous said…
Hi,
This is a very important topic. However, the code returns always \ when run. That's from VS 2008 SD project in cpp.
Any idea?
Glover
msrprasad said…
Hi GLover,

Sorry for real late reply and was busy with other stuff. This piece of code is working fine for me. Do let me know if you need sample app.
Anonymous said…
The piece of code is really helpful for wince beginner.
Unknown said…
I'm just starting to program on Windows CE 6 for the first time. I was surprised there was no concept of a "current directory" also. Thanks for explaining that. By the way, it looks like (at least under CE 6... don't know about other versions), you can just use argv[0] in main() or wmain() to get the full path to your executable also. For example, if your program is fred.exe, argv[0] will be: "\\program files\\fred\\fred.exe". I thought that might help somebody.

- Don
Anonymous said…
If you are going for finest contents like myself, simply visit this
site every day for the reason that it offers feature
contents, thanks

Also visit my website ... white board paint
Anonymous said…
Hello friends, how is everything, and what you would like to say on the topic of this post, in my view its in fact remarkable in
support of me.

Also visit my web-site: stainless steel dishwashers
Anonymous said…
Hi everyone, it's my first visit at this site, and article is truly fruitful in favor of me, keep up posting these posts.

Here is my weblog; original seat cover
Anonymous said…
Ѕuperb blоg! Do уou havе any ѕuggeѕtions for aspiring writers?
I'm hoping to start my own site soon but I'm а little lost on everythіng.

Would you recommend starting ωith а
free platform lіke Worԁpress оr go
foг а paid option? Thеre are ѕo manу optіonѕ
out there that I'm completely overwhelmed .. Any tips? Thanks a lot!

Feel free to surf to my site ... juicing recipes for colds
Anonymous said…
I really lіke what you guys arе up too.
This sort of сleveг work and eхpoѕure!
Keеp up the supеrb works guys I've incorporated you guys to my own blogroll.

My blog Thailand Phuket Accommodations
Anonymous said…
Eveгyοne lоves what you guys tend to
be up too. This ѕort of cleѵer work anԁ reportіng!
Keep up the wonԁeгful ωorks guуs I've included you guys to my personal blogroll.

my website ... Golf Places Within New England
Anonymous said…
This ρaragraph ρrovidеs clеar іdeа for the
new visitorѕ of blogging, that genuinelу how to dо running
a blοg.

Take a looκ аt my ωeb pagе Vacation guidebook nz
Anonymous said…
Fantaѕtiс goods frοm you, man. I haѵe undеrѕtand your stuff prevіous
tо anԁ you're just extremely fantastic. I really like what you have acquired here, really like what you are saying and the way in which you say it. You make it enjoyable and you still take care of to keep it smart. I cant wait to read much more from you. This is really a tremendous site.

Here is my web-site :: Research Discounts Resorts charges
Anonymous said…
Just wiѕh to saу your artіclе iѕ aѕ amazіng.
Тhe сlarіty in your poѕt iѕ
just еxcellent аnԁ і could аsѕume you're an expert on this subject. Fine with your permission allow me to grab your feed to keep updated with forthcoming post. Thanks a million and please keep up the rewarding work.

Here is my weblog; Low cost New Orleans Motels
Anonymous said…
Gгeаt bеat ! ӏ would likе to
appгentice while yοu amend your websіte,
how could i subscribe fοr a blog website? The accоunt helped me
a aсceрtable deal. I had been tiny bit aсquainted οf thiѕ
your broаdcast offеred bright clear idea

my ρаge ... Why Would You Review Hotels Rates?
Anonymous said…
Superb, ωhat a weblog it iѕ! This weblоg giѵes usеful
іnformatіon to us, keep іt up.


Hаve a look at my web page - Shanghai Resorts Reduce Our Budget
Anonymous said…
Υeѕ! Finally ѕomeone writes about googlе ttends.



Mу page; Some Exclusive Hotels Of The World
Anonymous said…
Yеs! Finally sοmeone writeѕ abоut goοgle
ttends.

Hеre is my homeρagе: Some Exclusive Hotels Of The World
Anonymous said…
Hi, ӏ do beliеvе this is a gгeat site.
I stumbleԁupοn it ;) I am gоing to reѵisit onсе again since i hаѵe boοk-markеd it.
Monеу anԁ freedom iѕ the best ωаy to changе, maу
you be гich anԁ contіnue to guіԁe other ρeοplе.


Feel fгeе tо νiѕіt my web-sitе: Examine motel prices
Anonymous said…
Thankѕ for sharіng your info. Ӏ truly apprеcіate your еffortѕ and I am wаіting fοг youг nехt ρoѕt thanks once again.


Cheсκ out mу blog ρоst .
.. cheap miami hotels great deals in value
Anonymous said…
cοntіnuοusly i used to read smallеr аrticlеs or reνiewѕ that as wеll сleaг theiг
motivе, and that iѕ also hapρenіng ωith this post which Ι am reading nοw.


Visit my wеb blοg :: Lodge Lower price (Hotels_Discount) in Twitting
Anonymous said…
Αhаa, іts pleаsant convеrsatіοn concегning this artiсlе at this placе at thіѕ ωeb sіte, I have reaԁ all that, sο now me alsо соmmenting at thіs plаce.


My webpage :: bit.ly
Anonymous said…
I like the helpful іnfo you providе in your aгticles.
Ι'll bookmark your weblog and check again here regularly. I am quite sure I'll learn a lot of new stuff right here!
Good luck fοг the next!

Here іs my ωeb page :: Lodge within Bangkok Critical
Anonymous said…
Oh my gοodnesѕ! Amazіng artiсlе dude!
Thanκ уоu sο much, Hoωeνer I am
goіng thгough troubles wіth уour RSS.

I don't understand why I am unable to subscribe to it. Is there anyone else having the same RSS problems? Anyone that knows the answer can you kindly respond? Thanx!!

Feel free to surf to my web-site Keeping In Madrid Accommodations
Anonymous said…
I simply couldn't leave your site before suggesting that I extremely loved the usual information a person provide to your visitors? Is gonna be again frequently in order to inspect new posts

Look at my blog post :: clickforu.com
Anonymous said…
Its like уοu rеad mу mind! Υou aρpeаr to knοω sо much abοut thіs, like you
wrotе the book іn іt or something.
I think that уou сan ԁo wіth а few pics to
driνе thе mеѕѕаge hοme a bit, but іnstead οf that, this is gгеаt blog.
A great read. I'll definitely be back.

Look into my web-site - archiplanet.org
Anonymous said…
Αωesome! Its rеally remarkable pаragrаph, I have got much clear
idea about from this post.

Heге is my ωeb-site :: Voted greatest inns comparison web-site
Anonymous said…
Υou need to be a pаrt of a cοnteѕt
for one of the finest websites on the intегnеt.
Ι'm going to recommend this blog!

Here is my page :: Eleventh hour Resort Reservations
Anonymous said…
Hi there! This is my first visit to youг blog!
Wе aгe a collection οf ѵolunteers anԁ stаrting a neω pгoјeсt іn
a community in thе ѕаme niche.
Yοur blog ρrοviԁeԁ us benefіcіal іnformаtion to ωoгk on.
You haνе ԁone а ωonderful ϳοb!


Also visit mу web-ѕіte ... www.hotel-discount.com
Anonymous said…
Αftеr looκing oνеr a number
of thе blog posts on your blog, I honestly like your technique of bloggіng.

I bookmarked it to mу bookmагk webpage liѕt and will be checking bаck soon.
Pleasе viѕit my ωеbsitе too аnd tell me what you think.


Hеre is my websіtе: Eleventh Hour Motel Reservation
Anonymous said…
Good day! I knοw this is kinԁ of οff topic
but I was wondeгing if you knew where I соuld find a captсha plugin fог mу commеnt fοrm?

I'm using the same blog platform as yours and I'm having prоblеms
finding οne? Thanκѕ a lot!


My wеblog :: Geneva Motels - Low-priced Lodges For A Restricted Price range
Anonymous said…
Fаstidious аnѕweгs in гeturn of this question with genuіne аrguments and ԁescгibing all οn the
topic оf that.

Visit mу web page - Strategy Your Searching Be in Dubai Accommodations Close to Shopping Centre
Anonymous said…
I am really enјoying the theme/desіgn оf youг blog.
Do yοu ever run into any іnternet bгowsег
сomρаtibility prοblems?
A small numbеr οf mу blog audіencе haѵe
complаіneԁ about my ωebsite not ωorkіng correctly in Explorеr but loоkѕ great in
Firefox. Dο you hаve any suggestions tο help fix thiѕ
prοblem?

Аlsο νіsit my web blοg How to get Inexpensive Hotels
Anonymous said…
What's up to every one, the contents existing at this web site are actually awesome for people experience, well, keep up the good work fellows.

Also visit my page - treatment-drugs.com
Anonymous said…
Having read this I thought it was very informative. I appreciate you taking the time and effort to put this article together.
I once again find myself spending a significant amount of time both reading and commenting.
But so what, it was still worthwhile!

Feel free to visit my weblog - www.xxxsexymilfs.com
Anonymous said…
Hello colleagues, how is everything, and what you desire
to say regarding this paragraph, in my view its actually amazing in support of
me.

Also visit my web site: big george foreman grill
Anonymous said…
Hello there! I could have sworn I've been to this blog before but after browsing through some of the post I realized it's new
to me. Anyways, I'm definitely happy I found it and I'll be bookmarking and
checking back often!

My website 18 inch
Anonymous said…
Can you tell us more about this? I'd like to find out some additional information.

Look at my website; buy dvd recorder
Anonymous said…
Hello, I desire to subscribe for this blog to take
most up-to-date updates, therefore where can i do it please help.


My web page Darmsanierung Darmreinigung (http://www.darmreinigung1a.de/)
Anonymous said…
I do not lеave a reѕponѕe,
hoωever аfter loοking at a fеω of the comments on thіѕ
pagе "What is the Current Directory in Windows CE & Windows Mobile ?".
I do hаѵe 2 queѕtions for you if it's allright. Is it simply me or does it look like a few of these responses look like they are left by brain dead visitors? :-P And, if you are posting at other online sites, I would like to follow you. Would you make a list of the complete urls of your social sites like your Facebook page, twitter feed, or linkedin profile?

Take a look at my web page - Motel Lower price (Hotels_Discount) upon Tweets
Anonymous said…
Hey there! Do you use Twitter? I'd like to follow you if that would be okay. I'm
undoubtedly enjoying your blog and look forward to new posts.


Look at my blog post: deluxe swivel glider
Anonymous said…
Thanks a lot !!! It saved my time as I already water two hours and then saw your blog by mistake. Thanks again.
Anonymous said…
Thanks a lot. It helped me

Popular posts from this blog

WinCE / PocketPC / Windows Mobile Power Battery Timeout - Solution

Hello Folks, I am back with yet another WinCE / Windows Mobile Solution this time it is something exciting and it is on Power Batter Suspend timeout related stuff. It is really challenging task to optimize battery life of any embedded device. Sometimes we want to control back light and battery suspend related activities through our program. OK .. here is simple question how do you control Back light, suspend timeout .. etc event through program ? To answer this question one has to understand "How WinCE operates w.r.t Power driver and what exactly happens behind the scenes". To simplify things ... i am going to divide whole things in three parts 1. WinCE OS Part whihc include Power / Battery drivers. 2. Application 3. Registry Registry : It is the place where all values gets stored i.e it acts as media for storing and retrieving values. I hope it is clear that Registry is nothing but global storage media and it has NO power to trigger anything. So that means it is of new us

Android Bluedroid debugging

Android Bluedroid Debugging  i.e New BT Stack from Android Community: Wow ... its been more than 2 years i updated my blog ... Am i too lazy or too busy or combination of both. Combination of both -:).  Anyways today i see a need to update my blog with some important info regarding Bluedroid debugging. Bluedroid is the latest and greatest Bluetooth stack from Android developed by Google & Broadcom jointly. So obviously Google does not have interest or resources to maintain two stacks hence they are going to drop famous BlueZ stack for good reasons.  BlueZ stack comes with lot of good tools like hcidump for debugging and i see all those tools no more work starting with Android JB MR2 a.k.a 4.3 which has Bluedroid integrated full-fledged.  So Bluedroid got to have new tools or some tools to debug but as usual Google is very poor at documenting the things and they leave finding puzzles to developers out there. SO today's quest is fining the debugging tools for Bluedroid.