|
I gave you a link to the API in my previous message, you need to go and study it.
|
|
|
|
|
|
|
|
|
Hi,
I built a function library (dll) in MS-Visual Studio 2022 using C/C++, to be accessed directly from Excel cells via VBA code.
When I call the dll in the 32-bit version of Microsoft 365 Excel, no error occurs. But when I compile the dll for x64 and run it from the 64-bit version, an access violation occurs in the function arguments.
Summarizing the project in a single function:
---------------------------------------------------------------
.cpp file:
extern "C"
{
__declspec(dllexport) double __stdcall fA(INT64&);
}
double __stdcall fA(double& a)
{
return a;
}
-------------------------------------------------------------
VBA da planilha Excel:
Declare PtrSafe Function fA _
Lib "C:\dll64\dll64.dll" (ByRef a As Double) As Double
-------------------------------------------------------------
|
|
|
|
|
Why did you declared it as
double __stdcall fA(INT64&); not as
double __stdcall fA(double&);
|
|
|
|
|
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
|
|
|
|
|