|
I'm trying to get some code to run to work around another issue, and for the life of me, I cannot make the VS2008 linker happy.
This is for a smart device, Windows Embedded Compact 7, but I think the target is only a symptom. I've tried this against 3 different SDKs for VS2008 as well as EVC++ (going way back) and two different SDKs - all have the same issue.
I need the application to run OLE. So, I created a very simple dialog app - think default code base, C++. It compiles and links. I then add one call: "OleInitialize(0);" and I get this:
Quote: 1>Linking...
1>OleTest.obj : error LNK2019: unresolved external symbol OleInitialize referenced in function "public: virtual int __cdecl COleTestApp::InitInstance(void)" (?InitInstance@COleTestApp@@UAAHXZ)
You can say I need to add an input to the linker line for ole32.lib, but it still fails. Oddly, VS2008 shows that I've inherited these from the solution. Of course the desktop links fine.
Any random or "oh crap, yeah, I had that problem" ideas? It's almost as if the ole32.lib doesn't have OleInitialize. I could believe that for one SDK but not 5.
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
|
|
|
|
|
As rough guess, the linker is not able to find the ole32 library for the embedded platform target (the reason I really don't know).
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
Well that's the obvious thing, but for the life of me I don't know why. I have other code that links with a few non-default libraries, and these are found fine. I searched my SDKs, and all of them have the library in question.
Very weird.
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
|
|
|
|
|
|
Give that man a cigar!
It had to be something stupid like that - I didn't pick up on that because if I hit :: - OleInitialize is actually in the popup. I guess it's in a header file but not in the binary.
Thank you
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
|
|
|
|
|
Charlie,
charlieg wrote: I guess it's in a header file but not in the binary.
Thank you
You are welcome.
|
|
|
|
|
I am working on c++ desktop application , i have to allow one time access for each employee per a day,
the question is how to interact with access control and open the door through it
(the access control has its dadecated software to open the door)
a looked for the API from its proper website but they do not offer it
now i have just the access control driver.
|
|
|
|
|
The question is impossible to answer since we have no idea how the access control software works. You need to contact the manufacturers of the door for help.
|
|
|
|
|
Message Closed
modified 15-May-23 19:06pm.
|
|
|
|
|
asked and answered in QA, I think.
Keep Calm and Carry On
|
|
|
|
|
|
First off, I'm not asking for anyone to write code for me. I would like to programmatically drop a Microsoft Project application into my Windows application in a specified location and then be able to drag and drop a file onto the container app? Any hints on how? Thanks
|
|
|
|
|
Glenn Meadows 2022 wrote: programmatically drop a Microsoft Project application into my Windows application What exactly do you mean by that? As to your second question, drag and drop of files is fully supported in Windows; Google will find you plenty of samples.
|
|
|
|
|
Glenn Meadows 2022 wrote: I would like to programmatically drop a Microsoft Project application into my Windows application in a specified location... This reminds me of what COM was used for decades ago.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
<pre lang="C"></pre>In my program, I am asking the user to input a date(in just integers ie 12 31 2019 367) and the number of days they add to it. In one of my functions, this is precisely what I am doing.
The user inputs 12 31 2019 367, and the program is meant to print 1 1 2021, but instead prints 1 1 2020(a year behind)...
What I did(Sorry for a lot of code, I tried to keep it simple and clean):
int days_in_month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
void add_days_to_date(int *mm, int *dd, int *yy, int days_left_to_add)
{
int days_left_in_month;
while(days_left_in_month > 0)
{
days_left_in_month = days_in_month[*mm] - *dd;
// days_left_in_month = days_in_month[*mm] - *dd;
if (days_in_month[2] && is_leap_year(*yy) == true)
{
days_left_in_month++;
}
} // end while
printf("after while\n");
if(days_left_to_add > days_left_in_month)
{
days_left_to_add -= days_left_in_month;
*dd = 1;
if(*mm == 12)
{
*mm = 1;
(*yy)++;
}
else
{
(*mm)++;
}
}
else
{
*dd += days_left_to_add;
days_left_to_add = 0;
}
}
int main()
{
int mm, dd, yy, days_left_to_add;
printf("Please enter a date between the years 1800 and 10000 in the format mm dd yy and provide the number of days to add to this date:\n");
scanf("%d %d %d %d", &mm, &dd, &yy, &days_left_to_add);
// printf("\nREAD\n");
//These are pointers, so they have to be at certain location i.e. int* mm = &mm
add_days_to_date(&mm, &dd, &yy, days_left_to_add);
printf("%d %d %d\n", mm, dd, yy);
}
What I got after inputs:
Inputs: 12 31 2019 367
Output: 1 1 2020(meant to be 1 1 2021)
Thank you in advance and for your time and patience...</pre>
|
|
|
|
|
You have to debug your code to see where, how and why it "calculates" wrong result!
|
|
|
|
|
Your code is somewhat confusing, but I did notice the following:
int days_left_in_month; while(days_left_in_month > 0)
{
days_left_in_month = days_in_month[*mm] - *dd;
if (days_in_month[2] && is_leap_year(*yy) == true) {
days_left_in_month++;
}
}
The actual logic needed is as follows:
Set days_in_year to the actual number of days up to the date given, which in the case above should be 365.
Add days_to_add to days_in_year.
While days_in_year > 365
{
add 1 to year
subtract 365 from days_in_year
}
Use the remaining value of days_in_year to calculate the month and day.
Obviously an adjustment for leap years will be needed somewhere in there.
|
|
|
|
|
As Victor was saying, this is the tough part of a programmer's job: finding the errors in your code. Most of the time you are on your own when doing it but in this case I'll try to do part of it with you hoping the experience will be useful.
Before we start, when posting code here, try to paste it between the <pre></pre> tags. It makes it for a much nicer and easier to read code.
int days_in_month[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
void add_days_to_date (int* mm, int* dd, int* yy, int days_left_to_add)
{
int days_left_in_month;
while (days_left_in_month > 0) Now, ask yourself, what is the value of days_left_in_month when the computer tries to evaluate the while loop for the first time? The answer is that it is not known. This is an "uninitialized local variable" bug and it is very common. The compiler has reserved space for the variable but its content can be anything. We have to fix this.
while (days_left_in_month > 0)
{
days_left_in_month = days_in_month[*mm] - *dd;
if (days_in_month[2] && is_leap_year (*yy) == true)
Oops, here is another bug: you wrote days_in_month[2] which is 28 and clearly not zero but what you probably had in mind was more like:
if (month == 2 && is_leap_year(*yy) == true)
If we fix the two errors we found your code will be looking something like this:
void add_days_to_date (int* mm, int* dd, int* yy, int days_left_to_add)
{
int days_left_in_month;
days_left_in_month = days_in_month[*mm] - *dd;
if (*mm == 2 && is_leap_year (*yy))
days_left_in_month++; Now it's really the time to start a loop but this loop will have to run until the days_left_to_add is greater than days_left_in_month .
Here I'll stop and let you finish the code. Post back the result and I'll give you more feedback on algorithm and style.
EDIT - I see that while I was writing my long convoluting answer Richard had already made the same points in a more concise form
Mircea
|
|
|
|
|
Yes, mine was concise, but your comments still added some good detail.
|
|
|
|
|
Hi
I am getting invalid comparator for the following code and I just dont get it at the very end there is always a path to return
struct usingrange
{
ESDID esdid;
int start;
int end;
usingrange() { start = 0; end = 0; return; }
bool operator<(const usingrange x) const {
if (esdid <= x.esdid) return esdid <= x.esdid;
if (start <= x.start) return start <= x.start; if (end <= x.end) return end <= x.end;
else
return FALSE;
|
|
|
|
|
Shouldn't you be passing usingrange as a reference to your comparison function?
bool operator<(const usingrange& x) const
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
It’s a member of key type
|
|
|
|
|
this is were I am getting the exception at the line with STL_VERIFY
template <class _Pr, class _Ty1, class _Ty2,
enable_if_t<is_same_v<_Remove_cvref_t<_Ty1>, _Remove_cvref_t<_Ty2>>, int> = 0>
constexpr bool _Debug_lt_pred(_Pr&& _Pred, _Ty1&& _Left, _Ty2&& _Right) noexcept(
noexcept(_Pred(_Left, _Right)) && noexcept(_Pred(_Right, _Left))) {
const auto _Result = static_cast<bool>(_Pred(_Left, _Right));
if (_Result) {
_STL_VERIFY(!_Pred(_Right, _Left), "invalid comparator");
this is my code
struct usingrange
{
ESDID esdid;
int start;
int end;
usingrange() { start = 0; end = 0; return; }
bool operator<(const usingrange& x) const {
if (esdid < x.esdid)
return esdid < x.esdid;
if (start < x.start)
return start < x.start;
if (end < x.end) return end < x.end;
else
return x.end < end;
when I change mt code to
bool operator<(const usingrange& x) const {
return start < x.start;
}
everything works I dont get it the operator is excepting a bool retrun code true or false in either I retrun that
|
|
|
|
|
Does your ESDID class have an operator<() function? If not, add one.
|
|
|
|
|
Thank you so much actually everything is a structure I am a very open person
I got to tell you something you C++ guys a geniuses
|
|
|
|
|