 |
 |
This message board is for managed and mixed-mode C++ programming only: Managed C++ in VC++.NET or C++/CLI. Please post all standard C++ programming questions in the Visual C++ board[^].
cheers,
Chris Maunder
CodeProject.com : C++ MVP
|
|
|
|
 |
I am receiving a date structure in "24-9-2016 13:30" format. Now I want to convert time value to specific timezone, I am doing calculations and have number of hours to add or substract.
So I don't know: how can I initialize tm struct with the date value I have? how to add or substract hours in tc struct variable to get required date?
my intention is
Date received "24-9-2016 13:30" and 5 Hours to add so final Date: "24-9-2016 18:30"
time_t tempTime
time(&tempTime);
struct tm *initStruct = localtime(&tempTime);initStruct ->tm_year = 2016;
initStruct->tm_mon = 9;
initStruct->tm_hour = 13;
.
.
.
please provide inputs.
modified 5 days ago.
|
|
|
|
 |
I am not sure what this has to do with Managed C++. However, the time, _time32, _time64[^] function describes the content of a time_t value, which you can easily initialise with a user defined time. I have not come across a date_t type, where is it defined?
|
|
|
|
 |
Sorry, if I used wrong group to post. I have updated post with some of the steps I tried, please check and let me know if is there any solution available.
|
|
|
|
 |
Since all those fields are integers you can add, subtract or replace any of them. You should check that the values are valid in terms of the calendar, although the mktime, _mktime32, _mktime64[^] functions will attempt to normalise a tm structure into a valid time. There are many other useful functions, and you should study the documentation to see which ones will help you.
|
|
|
|
 |
Yes, all these are integers, so I can perform addition or subtraction, but it is not handled well in below cases-
if hours are added
Like 4.5 then 13 hours should become 18:30
Or more than 24 then date should modify
In above cases I will need to add additional code depending on hours value, which is bad, isn't there any system method which will modify entire structure depending on the value assigned
|
|
|
|
 |
If you want to add partial hours, days etc. Then use mktime (as I advised in my previous comment) to convert your tm structure into a time_t value. you can then just add or subtract the number of seconds in your time increment.
|
|
|
|
 |
ok, so here is what I did now-
time_t tempTime
time(&tempTime);
struct tm *initStruct = localtime(&tempTime);initStruct ->tm_year = 2016;
initStruct->tm_mon = 9;
initStruct->tm_hour = 13;
int hoursToAdd = 4.5;
initStruct->tm_hour = initStruct->tm_hour + hoursToAdd;
time_t myTime = mktime(initStruct);
printf( "%s", ctime( &myTime));
any idea whats going wrong here?
|
|
|
|
 |
int hoursToAdd = 4.5;
That is not a valid statement so it will not even compile. You cannot assign a floating point number to an integer variable.
|
|
|
|
 |
Yes, my bad. well in that case my original question reopens how can I assign partial hour to tm struct to enable it to give valid date value.
|
|
|
|
 |
You really (and I mean really) need to go and study the documentation which explains what each field represents. If you have some number of hours and some number of minutes then you need to add them separately to each field. You should also step through your code with the debugger so you can see at each step what are the values of the various fields.
|
|
|
|
 |
Thank you very much Richard for your kind help. I really appreciate your time and effort.
|
|
|
|
 |
Please I am new to c++ as I have been learning it on my own for months now, and I will like to know how to add the gtkmm lib to visual studio 2015. Any help will be much appreciated.thanks
|
|
|
|
|
 |
I have a MFC SDI application created and added CDialogBar to set as main toolbar as you look in the screenshot I attached. It works well on every windows os(Xp, 7, 8, 8.1, 10) of windows tablet devices except only Microsoft Surface.
Please look at this screenshot. the CDialogBar menu is cut off. I don't know reason why this happens. The drawing issue always only occurs on Microsoft Surface 3 which has high resolution and high DPI screen and it works good on any other tablet. This is very strange issue so I dragged toolbar(CDialogBar) and dropped down on any place then the toolbar was re-painted clearly. So.. through this issue, I am sure that this is re-drawing issue. Is there any drawing function to redraw that area?
I am attaching my minimized source code to represent drawing issue.
Drawing Issue Screenschot
Minimal Source code to represent drawing issue
Please help me. Thanks
Operating System: Windows 10
Tablet: Microsoft Surface 3
Tool: Visual Studio 2015 Update 3
DPI rate: 150%
To resolve this issue, I have been trying to set DPI Awareness property to None, but the graphics Interface was not good and they were all stretched. I really don't like this solution, I have to find other solution without setting DPI Awareness to "None".
|
|
|
|
 |
From the comments in this Visual Studio blog post: Visual Studio “15” Preview 4
Eric Battalio [MSFT] would like to hear from C++/CLI devs if there are issues we are having.
"We would like to learn more about issues developers have with C++/CLI. Please email me [email protected]"
I added another plea for a fix to the std::unique_ptr bug (can't pass it by value in /clr code). You may wish to add more. Please do so that he hears from us C++/CLI devs the minority that we are....
John
|
|
|
|
 |
This isn't really the right forum for your message, since it's not a question.
You should probably post it in The Insider News[^] instead.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
 |
hmm, beg to differ in my interpretation of the purpose of this area. I marked it as Type: 'News' and this is listed as the Managed C++/CLI discussion area. That may explain a general lack of actual discussion however. I may post there too. Thanks
|
|
|
|
 |
Yes, but there's a reason the big red button at the top of this forum says "Ask a Question", rather than "New Discussion".
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
 |
I've used pin_ptr<> for years now but just came across interior_ptr<>. I supposed I may have been sheltered not needing it but can anyone illustrate why I'd prefer interior_ptr over pin_ptr?
John
|
|
|
|
 |
Hi Guys.
I'm just conducting a research. Is it possible to create a round shape on screen that can be invisible or not seen by human eye,which can be seen by software that perform something like bio-metric reading/face detector. Its can not be only a shape even if its some sort of light/image that is impossible for a human to see but possible to software doing similar as face detection?
If this is possible how could one go about doing this and what this form is called and also if any knows samples, documentation about this.
I know this maybe a complex question but as I've said I'm conducting a research on this.
|
|
|
|
 |
If it's visible on screen then it must be visible to the eye. I think the laws of physics apply.
|
|
|
|
 |
Hi, thanks. but what I mean is that if it can be something that will not block a user from seeing from the screen. Something like water mark. even if its visible but a user must be able to see through it clearly.
|
|
|
|
 |
Yes, it's called alpha blending, where an image is semi-transparent.
|
|
|
|
 |
Thanks and this looks as if its exactly what I'm looking for, but what how can I make this be sort of transparent? I mean the whole form with one picture to be sort of transparent so that I can see through it while the picture is not 100% invisible but be a see through?
I want my form to be OnTop always and it must not block me from using a computer, I must be able to see through it with the picture or make it show lets say after 20 seconds and be 100% transparent and after 20 seconds be maybe 99.8% or 99.9% transparent. The transparent must be something which I can also detect by maybe a face detector technique.
How can I achieve this? Thanks again.
|
|
|
|
|
 |
I have the following program and I am trying to do the conactenation of two strings using overloading operator "+", but I am getting error in function "String operator+ (String box)" and line "box4 = box1 + box2".
Why doesn't show my string concatenated ?
#include <iostream>
#include <cstring>
using namespace std;
class String
{
public:
char *sir;
String()
{
cout << "\n String() default called." << endl;
}
String(char *sir)
{
cout << "\n String() parameter called." << endl;
if (this->sir != NULL)
delete this->sir;
this->sir = new char[strlen(sir)+1];
strcpy(this->sir, sir);
}
String(String &box)
{
cout << "\n String() copy constructor called." << endl;
this->sir = new char[strlen(box.sir)+1];
strcpy(this->sir, box.sir);
}
void setString(char *sir)
{
cout << "\n setString() called." << endl;
this->sir = sir;
}
char *getString()
{
return sir;
}
String operator=(String box)
{
cout << "\n String() Assigment operator called." << endl;
String temp;
strcpy(temp.sir, sir);
strcat(temp.sir, box.sir);
return temp;
}
String operator+ (String box)
{
String temp;
strcpy (temp.sir, sir);
strcat (temp.sir, box.sir);
return temp;
}
};
int main()
{
String box1;
box1.setString("Geeksforgeeks");
cout << "\n Box1::sir: " << box1.getString() << endl;
String box2;
box2.setString("GeeksQuiz");
cout << "\n Box2::sir: " << box2.getString() << endl;
box1 = box2;
cout << "\n Box1::sir: " << box1.getString() << endl;
String box3 = box2;
cout << "\n Box3::sir: " << box3.getString() << endl;
String box4;
box4 = box1 + box2;
cout << "\n Box4::sir: " << box4.getString() << endl;
return 0;
}
modified 4-Aug-16 13:21pm.
|
|
|
|
 |
What error, and where does it occur?
|
|
|
|
 |
Using Windows 7 and VS 2010 (soon 2015).
I’m writing a C++ managed code dll (managed.dll)which will be an intermediary between our unmanaged C++ code (program.exe) and a third party C# driver dll (tcbDriver.dll).
I don’t have access to the code for tcbDriver.dll. However, in the following example of managed.dll code, I use a TcbDriver class which accesses the tcbDriver.dll. So program.exe calls "__declspec(dllexport) int ConnectTCB()" in managed.dll, which in turns calls Connect() in tcbDriver.dll.
It works.
The problem is, I don’t know how get the managed.dll code to preserve the same instance of "work" or "tcb" for other methods that program.exe will call.
For example, in this case tcbDriver.dll will eventually make tcb.Initialized equal to "true", indicating it is done initializing the hardware.
However, managed.dll needs to use the same instance of "work" or "tcb" in another exposed function that it used to call Connect().
The exposed function "__declspec(dllexport) bool IsInitialized()" makes a new instance, so tcbDriver.dll doesn't ever make tcb.Initialized equal to "true", even after TcbDriver is done initializing.
namespace ManagedTCB
{
public ref class DoWork
{
TcbDriver::TCB tcb;
public:int ConnectTCB()
{
try
{
tcb.Connect();
}
catch(...)
{
return 0;
}
return 1;
}
public:bool IsInitialized()
{
return tcb.Initialized;
}
};
}
__declspec(dllexport) int ConnectTCB()
{
ManagedTCB::DoWork work;
return work.ConnectTCB();
}
__declspec(dllexport) bool IsInitialized()
{
ManagedTCB::DoWork work;
return work.IsInitialized();
}
How do I use the same instance of the tcb class in different exported functions? Thanks for any help,
Gary
|
|
|
|
 |
Actually, all I need to do is make the tcb variable static, as in
static TcbDriver::TCB tcb;
Gary
|
|
|
|
 |
I have the following code.
Why does not my x is displayed.
I do not understand, X is returned by the getX() function wich is called from the derived class SecondClass() through an object of type FirstClass().
Initialization of X was done using constructor function FirstClass(int x).
I did not want to use the initialization function like setX ().
#include <iostream>
using namespace std;
class FirstClass
{
private:
int x;
public:
FirstClass()
{
cout << "\n Default constructor FirstClass()." << endl;
}
FirstClass(int x)
{
cout << "\n Constructor FirstClass()." << endl;
this->x = x;
cout << "\n X = " << x << endl;
}
int getX()
{
return x;
}
};
class SecondClass:protected FirstClass
{
private:
int y;
public:
SecondClass(int x):FirstClass(x)
{
cout << "\n Constructor SecondClass()." << endl;
}
void printX(FirstClass& obj)
{
cout << "\n X = " << obj.getX() << endl;
}
};
int main()
{
FirstClass box1;
SecondClass box2(100);
box2.printX(box1);
return 0;
}
|
|
|
|
 |
Please do not post the same question in multiple forums.
|
|
|
|
 |
please help me on how to extract audio from video.
|
|
|
|
 |
That is a question for Google.
|
|
|
|
 |
In Microsoft Visual C++ how to use sub threads to achieve similar CListCtrl ?
|
|
|
|
 |
I am a student of BS(CS) "Computer Science" .
I have a project of "AES Code implementation in C++" and i have submit that project on 28 JUNE 2016
I have a technical issue in my code
Only serious programmers were needed. I can provide any sort of help (to understand my code)
thank you
|
|
|
|
 |
This is exactly the same "question" you posted in the thread immediately below, and again in QA earlier this week.
Reposting the same demand for free consultation over and over again will get you banned from this site.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
 |
Sorry but no one is going to download your project and debug it for you.
|
|
|
|
 |
can you tell me the reasons
|
|
|
|
 |
Because this is an open forum for answering questions, not for doing other people's work.
|
|
|
|
 |
Hello, This Taiming and I am a serious C++/MFC developer with 15 years experiences.
Please let me know what problems you have met in AES encryption.
|
|
|
|
 |
i am having trouble in AES code implementation in c++.Can any one help in c++ coding point of view
thank you
|
|
|
|
|
 |
i have seen these web pages and code it according to that algorithm
i am now in final position in that code and the problem is that it is not encoding correctly and decoding as well so could you help me in that case
thank you very much
|
|
|
|
 |
Without seeing your code neither I nor any other here can help.
If you just need working code, use an existing implementation.
Otherwise show your code and what you have tried / where it fails. To do this, edit your question and add the relevant code formatting it using the 'code' option above the edit window (should be not too much code).
Another tip is using an existing implementation with the same arguments and comparing the results. So you can detect if encryption, decryption or both are failing.
|
|
|
|
 |
[Note: Enquirer has send a mail to me containing the code]
You had asked for help in a public forum. Then you should let others participate in the discussion.
But the complete code would be too much to be posted here and I have no time to step through that amount of code. Especially because it does not contain comments and begins with the inclusion of other source files which is bad C/C++ style.
If you find someone who can help you should at least tell which of these "web pages" has been used by you and which code parts has been written by you or has been copied.
|
|
|
|
 |
Message Removed
modified 27-Mar-16 10:25am.
|
|
|
|
 |
Write a simple expression evaluator that takes a string like the following as input: 1+2*(3+4).
-Only integers need to be supported
-The following operators should be supported: +, -, *.
-Expressions within parenthesis should be evaluated first.
-Then the resulting expressions should be evaluated from left to right (no operator precedence)
-Example:
4+(4-(2*3)+1)+4 = 7
The code should be written in such a way to support additional operators.
Assume the existence of a function tokenise, which could take a string and return an array of strings, for instance
tokenise(‘1+(2*3)+4’) would return [‘1’,’+’,’(‘,’2’,’*’,’3’,’)’,’+’,’4’]
and the functions isNumber and asNumber which would return a Boolean and integer respectively on a single string input.
modified 17-Mar-16 14:43pm.
|
|
|
|
 |
Your homework should serve the purpose that you learn something. And that something isn't supposed to be how to get other people to doing your homework for you.
Your assignments will get more difficult over time - so if you don't start doing them yourself now you'll never be able to.
So sit down, think about it and try something. If you then encounter a specific problem, feel free to ask - that's the idea of these forums.
Also, there are a lot of articles here on CodeProject about expression evaluation. Take a look at those if you struggle to find a starting point.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|