|
Re: Use whichever type you are more comfortable with, although using WCHAR tends to give more flexibility if you ever need to port your code to some alternative platform.
I have been working with Microsoft VS for a while now and have not gotten out to play with others in a long time. I will go with that and stick with the WCHAR.
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
|
|
|
|
|
Daniel Pfeffer wrote: Richard MacCutchan wrote: If you make everything Unicode, you should not have any issues.
It depends on what you mean by Unicode...
Windows API and UI use UTF-16 (started with Windows-NT 4.0) but if you generate output for a SMTP/email/WEB you must use UTF-8. For UTF-16 you can use CStringW or std::wstring but for UTF-8 CStringA or std::string. UTF-8 is a multibyte string format but it has nothing to do with the old MBCS which depend on codepages.
In this case using CSting depended on the UNICODE define to make the code UTF-16 aware is now out of time and can shoot you in the foot.
Conversions between UTF-16 and UTF-8 can be done with the current MultiByteToWideChar and WideCharToMultiByte. But if you write more general software, do it with the stl:
wstring_convert<codecvt_utf8_utf16<wchar_t>> converter;
The bad thing is that the current C++ Visual Studio editor can't handle utf-8 string literals. It is a Windows application you know...
|
|
|
|
|
Windows XP, soon to be Win 7, Visual Studio 2008, C++
The Connect function wants an LPCTSTR. m_address is declared as WCHAR. This compiles, but is it OK to use the code in the title or is it bad to do in the long term?
My searches for: convert WCHAR to LPCTSTR turn up some things, but nothing that appears to fit. I think my work firewall is filtering things out.
Edit: I have found that it is not ok to use in the short term. When used with SetDlgItemText to put text in a dialog, it does not work.
Starting with a WCHAR m_address[ 32 ];
and the need to call a function that needs LPCTSTR, such as Connect(...) or SetDlgItemText() that wants LPCTSTR, what can be done to m_address to build an LPCTSTR device.
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
modified 24-Feb-15 17:20pm.
|
|
|
|
|
LPCTSTR is a typedef which will be generated as LPCWSTR (which is really WCHAR* ), or LPCSTR (which is really char* ), depending on whether your project defines UNICODE or not. In the Connect call, no conversion is required, the definition is merely telling you that m_address must be a pointer to a string in the appropriate character set. So if your project is generating Unicode it should be something like:
WCHAR m_address[] = L"128.56.22.8";
LPCWSTR m_address = L"128.56.22.8";
BOOL result = Connect(m_address, nPort);
And if non-Unicode
char m_address[] = "128.56.22.8";
LPCSTR m_address = "128.56.22.8";
BOOL result = Connect(m_address, nPort);
And if you wish to cater for the possibility that you may wish to build it for either type
TCHAR m_address[] = TEXT("128.56.22.8");
LPCTSTR m_address = TEXT("128.56.22.8");
BOOL result = Connect(m_address, nPort);
|
|
|
|
|
Re: LPCTSTR is a typedef which will be generated as LPCWSTR (which is really WCHAR*),
I had not realized that. Ok, now I am going to find that codeproject article(s) on the various types of string and study it. Enough of this messing around in the dark about strings.
Thank you Richard.
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
|
|
|
|
|
Happy to help. It's one of those things that once you get your head round it, it seems so simple (I hope). 
|
|
|
|
|
I am hoping for that. Enough fumbling around in the dark.
thank you for your help Richard.
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
|
|
|
|
|
Visual Studio, C++, TCP utility
I am creating a utility to handle TCP/IP I/O for a telemetry project. It has a rather high and continuous bandwidth. Four or maybe more instances will be run at one time. It seems to me that now is the time to take this class and put it into a DLL. Is this an appropriate use of DLL? Do you have a favorite article or list of important things to remember when creating my first DLL?
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
|
|
|
|
|
ok, I guess you're continuing your TCP API project from (somewhere below this in the forum)..
looking at this :-
bkelly13 wrote: Four or maybe more instances
I (personally) think that alone is not necessarily a good indicator of when to use a dll - you're going to create 4 instances of a class that implements an API, on the face of it, what is there in this that says that class/code needs to be in a dll ? you program will start, load the dll is if has to, instantiate x copies of the class as required, but wouldn't really care if the code is in a dll or not ...
So... you could say back to me, I need to use a dll :-
(a) so I can implement a plugin or make it easier to change just that API
(b) to encapsulate my API for deployment, particularly where I have multiple programs that all need the same thing, so they each use the same dll ergo code/api
this is only one consideration I guess Brian
|
|
|
|
|
If you want to separate out some of your functionality then a DLL is one way to do it. But unless you are sharing the DLL with other applications then it offers no particular benefit; a static library would be just as useful.
|
|
|
|
|
Replying to both posts:
Eventually I'll make this available to others to use. Then, from my reading, it becomes easier to incorporate into another project when built as a DLL. Until then, my plate is full in developing the message app (that uses the TCP IP project) and the TCP project itself and I don't need that extra step.
I'll leave it is as a static library until I am ready to share.
Thanks for your thoughts.
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
|
|
|
|
|
When choosing to go to a DLL, think whether you (or someone else) will be using these methods in another application, or whether you'd like an expandable interface via DLL based plug-ins.
A common example of DLL usage would be in implementing audio codecs (since any exe that plays audio can/would use it). Additionally, functionality can be expanded/removed from applications via DLLs. Plug-ins can be implemented using DLLs with a standard interface. The application can look for any DLLs with the standard plug-in interface and load what's available.
|
|
|
|
|
I am using CDHtmlDialog for my application and i want to use CHtmlEditView in CDHtmlDialog. I want to make HtmlEditor in DHtmlDialog for which i am using RichEdit control in DHtmlDialog and create CHtmlEditView over that RichEditControl. But When i am running that Html dialog RichEditcontrol is disabling due to Creation of CHtmlEditView.
I want sking in html and with this i want CHTMLView capability for making an editor as html editor in between html skin.
Just like toolbar and other backend UI in html with Editor in middle using HTMLView capability.
Can anyone please help that how i can use ChtmlEditView in DHtmlDialog to create sort of Html Editor.
Its running perfect with CDialog but having problem with DHtmlDialog.
Please help in this Regards.
modified 8-Jan-15 5:19am.
|
|
|
|
|
Member 11018967 wrote: when i do CDialog::oninitdialog it runs perfect but no with CDHtmlDialog::oninitdialog() That does not really tell us anything about the problem you are seeing. Please edit your question and add full details of what is going wrong.
|
|
|
|
|
My Question is that How we can use CHTMLEditView with DHTMLdialog at specific rect width and height.. When i create HTMLEDITCtrl/CHtmlView in DHTMLDialog it does not edit the text it becomes freeze..
How i can use CHTMLView in DHTMLDialog. Just want to make HtmlEditor that has buttons and backend UI is in HTML.
|
|
|
|
|
Member 11018967 wrote: it does not edit the text it becomes freeze.. This still does not tell us anything useful. If you want someone to help you then provide a proper detailed description of what your code is doing and where the error(s) occur.
|
|
|
|
|
Visual Studio 2008, c++
Class C_Messages works with various structures called messages. The initial configuration of the messages is by reading a text file and is rather extensive. C_Messages instantiates a class called C_Configuration to read the text file and perform all the startup work. Currently C_Messages instantiates C_Configuration then calls some functions handing C_Configuration pointers to the structures.
Is there some way that C_Configuration can be declare a friend of C_Messages and dispense with the functions just to set the pointers. I am thinking of something like this in C_Messages.h
Class C_Configuration;
Class C_Messages
{
…
Friend C_Configuration;
int x;
}
Then in file C_Configuration.cpp would be something like:
Class C_Messages
Int Do_This()
{
X = 2;
}
When I read the various forum questions on this none seem to apply to a simple relationship like this. Maybe its just not possible so I am trying make a simple question out of this.
EDIT
I just figured out part of it and why the compiler is saying the variable is not static. If I don't want static variables can I do something like hand over the this pointer to C_Messages to C_Configuration then C_Configuration can access the members of C_Messages?
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
modified 9-Dec-14 14:09pm.
|
|
|
|
|
What you have shown above doesn't really make sense. The use of the friend keyword is to allow access to protected or private variables of the other class, but you still need an instance of the class to access them. It's most useful when the friend class inherits the other one. If you are just interested in accessing the properties or methods of an object of another class, then you should make them public.
|
|
|
|
|
Re: Quote: The use of the friend keyword is to allow access to protected or private variables of the other class
That is the part I thought I understood.
Quote: but you still need an instance of the class to access them.
That is what I have now figured out, but I think only partially.
Quote: It's most useful when the friend class inherits the other one
Is the intent most useful or only useful. I am thinking only. I was thinking friend had a rather broader scope.
Class M starts running and creates class C to do a bunch of startup work. C is owned by M but does not inherit from M. C is deleted immediately upon completing its work.
Other than for startup (which requires some 80,000+ data items from a file), nothing in M needs to be public. But this entire app is and always be run in a closed system with strictly controlled ins and outs. I am leery of public variables but that would probably better than sending over a flock of pointers. Does the use of public seem to be my best option.
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
|
|
|
|
|
bkelly13 wrote: Class M starts running and creates class C to do a bunch of startup work. C is owned by M but does not inherit from M. C is deleted immediately upon completing its work. Then there is no need for them to be friends.
bkelly13 wrote: I am leery of public variables You can hid the variables by making them private, and creating public methods to get or set them, which is the generally recommended pattern in OOP.
At the end of the day it all depends on what each of your classes is supposed to do.
|
|
|
|
|
If all instances of C are owned by and created by an instance of M and there are no other clients of C then I can't see a lot of problem in making M a friend of C. You're essentially saying that C is a part of M you don't need all the time so you want to tear it off and discard it after some initialisation process.
Another way of doing it would be to introduce a new class, A that contains the bits of M that C needs to manipulate. M would contain an instance of A and pass a pointer to the instance to C when needed. That gives you a bit more future proofing and decoupling - both C and M don't depend on each other and just depend on A.
Yet another way would be to have a getter/setter interface on M but if C's the only thing that would want to use it then you're complicating the interface of M for no real reason.
Personally I'd go for the first and consider the second or third later if the requirements change and you need more flexibility.
|
|
|
|
|
First option was: Quote: then I can't see a lot of problem in making M a friend of C.
I was thinking that C would be a friend of M allowing C to see into M. Am I thinking wrong on that.
What is the syntax to make this declaration? C gets access to the variables of M, can change them, then C gets deleted.
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
|
|
|
|
|
You're right - I got things a bit bum backwards. Basically you want C to be able to look at the implementation details of M so you declare C a friend in M:
class M
{
friend class C;
};
should do the trick.
|
|
|
|
|
friend can be used to give another class access to the protected and private members of the class that specified friend.
If C_Messages want to access the protected and private members of the class C_Configuration then C_Configuration specified C_Messages as friend.
If you aggregate the class C_Messages so that is has a C_Configuration, you can only access the public members of C_Configuration in C_Messages. But with the friend specifier you can also access the protected and private members.
Sample code:
class C2;
class C1
{
public:
int public_var;
protected:
int protected_var;
private:
int private_var;
friend class C2;
};
class C2
{
public:
class C1 member;
void set_private_var (int v) { member.private_var = v; }
void set_protected_var (int v) { member.protected_var = v; }
};
void Test()
{
C2 obj;
obj.member.public_var = 100;
obj.set_protected_var(100); obj.set_private_var(200); }
Another solution is working with an intermediate class which specifies the friend. In this case you get only access to public and protected members of the base class.
Sample code:
class C1
{
public:
int public_var;
protected:
int protected_var;
private:
int private_var;
};
class C1B : public C1
{
friend C2;
}
class C2
{
public:
class C1B member;
void set_protected_var (int v) { member.protected_var = v; }
};
void Test()
{
C2 obj;
obj.member.public_var = 100;
obj.set_protected_var(100); }
modified 5-Jan-15 6:07am.
|
|
|
|
|
I am having one DLL file. when i crack that it becomes breakable and we can see the codings of that DLL in visual studio. but, i need that DLL as unbreakable(i.e., when trying to break that DLL it becomes a error report). If anyone know the answers, Please let me know. Thanks in Advance.
|
|
|
|