Jump to content
Tuts 4 You
Sign in to follow this  
Alzri2

Common questions in C++

Recommended Posts

Alzri2

Hello,


 


Anyone who has a (normal) question in C++, put it here.


Share this post


Link to post
Alzri2

I will start,


 


What is the best VS version to create MFC executables for WinXP (especially one that works without the need for VS_Redist... I've seen many !) ?


I've tried working in VS 2013 to create MFC that works on XP without VS_Redist but no luck :(


Share this post


Link to post
Kurapica

Regarding the version question : I would recommend using Visual Studio 2008 with SP1.


 


Make sure that you set your options like this :


 


2015_08_15_102516.png


  • Like 1

Share this post


Link to post
atom0s

I will start,

 

What is the best VS version to create MFC executables for WinXP (especially one that works without the need for VS_Redist... I've seen many !) ?

I've tried working in VS 2013 to create MFC that works on XP without VS_Redist but no luck :(

All versions including Visual Studio 2015 offer Windows XP support when building C/C++ binaries. Just be sure to target the proper toolset like this:

1Rlox3f.png

Keep in mind though that if you are using the Visual Studio CRT and not something else you are going to need the run time no matter how you compile. You can try static linking but in most cases you will run into needing the runtime installed either way. If you really need to avoid it entirely, look into using an alternative CRT library.

  • Like 1

Share this post


Link to post
Alzri2

Thankx for replies :)


 


Actually, before I installed VS 2008, I noticed it's VS 2015 that I had, not 2013 (sorry).


 



 


 


Make sure that you set your options like this

I've already set the options like that (in 2015, and now in 2008), but it creates other problems... u fix one, another one is waiting :D


Some of the problems:


"afxwin.h" include


MTD


unresolved @16_WinMain


 



 


 


All versions including Visual Studio 2015 offer Windows XP support when building C/C++ binaries

I know that, but I though there is an easier version to create XP supported apps


 



 


 


if you are using the Visual Studio CRT

Not using anything unusual (for me), just a dialog based MFC.


 


==========


 


I guess I'll have to go through more theory stuff then come back again !


Share this post


Link to post
atom0s

MFC made by Microsoft. So if you plan to use it you are going to need run times no matter what. No matter how you set options you are going to require them outside of static linking but still that will be hit or miss based on what you use.

Share this post


Link to post
Alzri2

I have seen many MFC apps that don't need runtime especially those made by crackers.


You can check those exe(s) made by lena in dealing with stack or HWBP tutorial...  it's tutorial #14 or #15 if my memory serves me right :)


Share this post


Link to post
mrexodia

Could be they are not MFC. Pure WinAPI also works good for simple graphical interfaces. MFC is just a nice C++ wrapper with extra features around the plain WinAPI. You can do everything MFC does by hand (although I do not recommend trying it).

  • Like 1

Share this post


Link to post
Alzri2
Could be they are not MFC

 

What if you see the imports and there are mfc ?!

I've checked and you can find it in lena tutorial #15, and it works in XP fine without the need for VS_Redist.

 

 

you can learn the basics of Win API here : http://www.winprog.o...rial/start.html

I know about this one, it's really good... on my to-do list.

But guys, I just wanna smth easy, at least for now, to create keygens just like I do in Delphi (especially D7). Simply, I wanna just practice writing algos in C++ (it's the best way I know to start with a new lang).

Share this post


Link to post
kao

I've checked and you can find it in lena tutorial #15, and it works in XP fine without the need for VS_Redist.

That one is made in Visual Studio 6.0, and uses mfc42.dll which is part of any Windows distribution since... forever? VS 6.0 was last Visual Studio version that could do that. :)

 

Starting from Visual Studio 2005, they introduced concept of redistributables. You can either have small EXE (~120kb for sample MFC app) and require users to install appropriate redistributable, or link with static libraries (same application is ~3MB in size) w/o requirements to install anything.

  • Like 1

Share this post


Link to post
Alzri2

After having some time with MFC, I ended up stuck with manipulating CString type.


 


I have a string and I simply want to change a specific character using "operator[ ]"... the weird part is that I can access the value, but I can't modify it


I guess it can be fixed using pointers but how ?:


 




CString test;

test = "Just a try";

test[2] = "w";



 


Found many answers in stackoverflow but for char type !


Share this post


Link to post
Kurapica

you should use "GetBuffer" which returns to you a pointer to a buffer which is considered writable.


 


then do your work and call "ReleaseBuffer" after you finish.


 


you can also use "SetAt" to change a specific char in the array.


 


anyway CString is a Microsoft invention so I really advise you to avoid using it.


Edited by Kurapica (see edit history)
  • Like 1

Share this post


Link to post
Alzri2

Thanx Kurapica and everyone :) 

 

 

anyway CString is a Microsoft invention so I really advise you to avoid using it.

So, what are the alternatives that could/shall be used easily with MFC ?

Share this post


Link to post
simple

 

Found many answers in stackoverflow but for char type !

 

Well because that's the best way to do it.

 

If you're coding C, then use memcpy() or string.h functions (memcpy() is better because u need specify # of bytes and less likely to cause memory overflow, unlike string.h functions) to copy your CString to a char* or char[]

 

For C++, do CString test = "string"; std::string CppString (test); Or CT2CA macro will work.

 

All (ascii strings at least) at the end of the day are either char* or char[]. CString, despite it's name - is not a real C string.

 

Even if u want use MFC (don't know why), char* or char[] should be interchangeable w/CStrings even w/out casting but definately w/a cast - so it makes no sense to use them.

 

std::strings will probably be easiest to use from a C++ compiler, u don't have to worry about memory management so much , but char* or char[] are fine too.

  • Like 1

Share this post


Link to post
Alzri2
Even if u want use MFC (don't know why)

Because creating GUIs there is very easy :)

 

 

 

char*

I have read that this is an old school way, and "string" objects are much better and safer, is that so ?

Edited by Alzri2 (see edit history)

Share this post


Link to post
simple

I wouldn't call them safer because u can still easily do overflows on C++ std::strings and it happens a lot.


 


char*/char[] is original C standard, which as of June of this year is the #2 most popular programming language (Java #1). Old school, yes but still very much alive & in demand.


 


std::string is probably the best option for c++. 

  • Like 2

Share this post


Link to post
Kurapica

Old school is the best :D


 


>https://www.youtube.com/watch?v=kTLQX1aavYw


  • Like 1

Share this post


Link to post
xSRTsect

I did a few tests my self and if you garantee that crt and mfc are getting statically linked you can go at least as far back as windows xp (assuming platform toolset has been properly configured)


  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×
×
  • Create New...