|
Can I cast the strTst* pt to an array of 2 pointers to strTst instance?
with
strTst *pt = &Sp1; although, there is a warning compiler issued.
I get the address of the Sp1 array.
I think since i get the address of a data object,then i can operate on the data object.
|
|
|
|
|
A cast should only be used when necessary, which isn't the case here.
EDIT: I'm compiling under C++, so maybe it's an error there, and only a warning in C.
|
|
|
|
|
How about this:
typedef struct {
int s1;
int s2;
int s3;
}strTst;
strTst spst1 = { 3,5,7 };
strTst spst2 = { 1,2,4 };
strTst* Sp1[2] =
{
&spst1,
&spst2
};
strTst** pt = Sp1;
void f () {
pt[1]->s1 = 0;
}
Mircea
|
|
|
|
|
You have declared Sp1 to be an array of pointers, each of which points to a strTst structure. So to get one of the pointers you just need normal array addressing, e.g. Sp1[1] returns the second element of the array. So all you need is:
strTst *pt = Sp1[1]; int value = pt->s2;
|
|
|
|
|
strTst *pt = Sp1[0];
pt->s1;
pt->s2;
pt->s3;
pt = Sp1[1];
pt->s1;
pt->s2;
pt->s3;
strTst **ppt = Sp1;
ppt[0]->s1;
ppt[0]->s2;
ppt[0]->s3;
ppt[1]->s1;
ppt[1]->s2;
ppt[1]->s3;
|
|
|
|
|
Hello everybody!
My working environment is: Windows 10, Visual Studio Community 2017 (and 2008 for older projects), programming takes place only in C/C++.
I need my program to be able to send emails with a PDF file attachment. The easiest way to send emails is to use ShellExecute with the parameter "mailto:someone@mail.com ... etc". But this method does not allow you to transfer attachments.
So I tried using MAPISendMail in a variety of variants found on the internet. Including Programmatically adding attachments to emails and many others. Almost all of them work fine on my computer.
However, when I trying to send an email on another computer, it leads to an error in the MAPISendMail function MAPI_E_NOT_SUPPORTED (code 26). In this case, the MAPILogon(Ex) function is executed without errors. Both computers, mine and the other, are on the same network and use the same mail server and Outlook as the client for users. On the other computer send/receive of the emails works perfectly. I searched the Internet for a long time for an explanation of this error, but found nothing. A search on the site CodeProject also did not give anything.
Please explain me what this error means and how to fix it. Thank you very much!
|
|
|
|
|
You need to examine the code that causes the error. That should give a clue as to why it occurs.
|
|
|
|
|
One of the simplest variants I taked from Sending Email with MAPI, "Attachment" example. It works perfectly on my computer, but cannot send email on other.
My send mail code fragment is:
LHANDLE lhSession;
ULONG result = lpfnMAPILogOn(0, NULL, NULL, 0, 0, &lhSession);
ULONG nSent = lpfnMAPISendMail(lhSession, 0, &MAPImsg, MAPI_LOGON_UI | MAPI_DIALOG, 0);
lpfnMAPILogOff(lhSession, 0, 0, 0);
Variable result is OK, but nSent is MAPI_E_NOT_SUPPORTED (code 26).
Complete example project there: Probe3.7z - Google Drive.
|
|
|
|
|
The issue is that some parameter that is in that SendMail call is incorrect according to the client or server that is handling the request. But there is no way anyone here can tell which it is. You need to capture more information somehow.
|
|
|
|
|
We had similar problems (sending e-mails with attachments). But since all our customers use MS Outlook as a standard e-mail application, we just implemented the Outlook automation. So the problem was solved.
|
|
|
|
|
Unfortunately, we do not use Outlook automation, we just have Microsoft Office installed with the Outlook mail program. In addition, it is important to me that my program can send an email from different computers. And finally I want to understand what's the matter here
|
|
|
|
|
It is not a big problem to implement the Outlook automation: about two to three working days (including tests and reading documentation).
The only problem I see is some of your customers may use some other (non-Outlook) mail-application, so my suggestion won't work for them.
|
|
|
|
|
|
I checked the registry keys on both computers (on my working one and on the other one having problems with sending mail programmatically). They match.
|
|
|
|
|
Well,
I can't think of anything else. You might have to debug this one. You can try resetting the MAPI settings with Fixmapi. I think fixmapi.exe is in the systems32 folder.
|
|
|
|
|
I think you still need to confirm the Outlook and MAPI versions; if you're looking for differences between computers.
Choose a specific version of MAPI to load | Microsoft Docs
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Hi
I'm getting problem running the sw I attach here below. I am trying to make an array of a certain class.
In the header I have the class then a .cpp with public methods. In the main I'm doing this:
<pre>#include "Anagrafica.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void cod (anagrafica arr,string n, string c,int chiave)
{ arr.codifica(n,c,chiave); }
void decod (anagrafica arr)
{ arr.decodifica(); }
int main()
{
ifstream file;
file.open("input.txt");
int N;
string n,c;
int chiave;
int chiave_input;
file>>N;
cout<<N<<endl;
anagrafica* Arr_ = new anagrafica[N];
for (int i = 0; i < N; i++)
{
Arr_[i] = anagrafica("ciao", "miao", i*25);
}
for (int i=0; i<N; i++)
{
file>>chiave;
file>>n;
file>>c;
}
for (int i=0; i<N; i++)
cout<<"inserire un valore intero"<<endl;
cin>>chiave_input;
}
here is header
<pre>#include<iostream>
#include<string>
using namespace std;
class anagrafica
{
private:
string nome_cifrato;
string cognome_cifrato;
int chiave_cifratura;
public :
anagrafica(string ="", string ="", int=0);
void setNome(string );
void setCognome(string );
string getNome();
string getCognome();
void codifica(string , string , int );
void decodifica();
void setChiave(int);
int getChiave();
void stampa();
};
I do not attach the public method here because problem is before using methods.
Problem occurs when I create instance of array of class anagrafica. At the end that is not an array. Program does not raise any exception in the for with i from 1 to N. As if array was of dimension N. But it isn't.
I tried also with the double pointer like this
<pre>anagrafica** Arr_ = new anagrafica*[N];
for (int i = 0; i < N; i++)
{
Arr_[i] = new anagrafica("ciao", "miao", i*25);
}
but Arr_ is of only 1 element,
the first no other
|
|
|
|
|
Roberto64_Ge wrote: but Arr_ is of only 1 element,
the first no other
How did you verify that? If you just looked in VisualStudio debugger, it will indeed show only one element because it doesn't know the size of the array. You can enter a length specifier in the inspector window (like Arr_,10) to make it show 10 elements.
Alternatively you can just say:
anagrafica *Arr_[10];
for (int i = 0; i < N; i++)
{
Arr_[i] = new anagrafica("ciao", "miao", i*25);
}
In this case the debugger will know the size of the array and show all elements.
Otherwise your code looks good as far as array creation goes.
Mircea
|
|
|
|
|
Problem is that I tried also with a costant as in your example but I could only see the first element.
In the snippet I posted some parts of the code is commented.
But when I remove comments app is working but the behaviour is that as if array was of 1 only element.
I will read further replies tomorrow, thank you.
|
|
|
|
|
The array variable needs to point to an array of pointers, so the syntax needs to be:
anagrafica** Arr_ = new anagrafica*[N];
for (int i = 0; i < N; i++)
{
Arr_[i] = new anagrafica("ciao", "miao", i*25);
}
Remember that Arr_ is a pointer to the actual array so it will appear to contain only one element. But you can check the contents with another simple loop.
You could make life much simpler for yourself by using one of the STL containers, such as vector<T> .
|
|
|
|
|
ok, i better checked, so thank you. Now, how is the syntax to access the method of any instance (of the class) pointed by the i element af Arr_. I don't find the way to do that. I mean that I need to do something like
Example : Arr_[i].setChiave(3)
By the way, may I call a method , example setNome(stringaNome) from within another method?
modified 8-Sep-22 10:22am.
|
|
|
|
|
Arr_[i]-> setChiave(3)
EDIT: And sure, one method can call another, subject to access controls (public, protected, private).
|
|
|
|
|
OK thanks.
By the way, may I call a method , example setNome(stringaNome) from within another method? I attach here three methods of the class, the greater calling the two small.
void anagrafica::setNome(string n_)
{
nome_cifrato=n_;
}
void anagrafica::setCognome(string c_)
{
cognome_cifrato=c_;
}
void anagrafica::codifica(string nome_chiaro, string cognome_chiaro, int chiave)
{
char car;
nome_cifrato = "";
cognome_cifrato = "";
for (int i=0;i <nome_chiaro.length();i++)
{
car = nome_chiaro[i] + chiave;
nome_cifrato = nome_cifrato + car;
cout<<"carattere "<<i<<" n in chiaro "<<nome_chiaro[i]<<" chiave "<<chiave<<" cifrato "<<car<<" nome incostruzione "<<nome_cifrato<<endl;
}
setNome(nome_cifrato);
for (int i=0; i<cognome_chiaro.length();i++)
{
car = cognome_chiaro[i] + chiave;
cognome_cifrato = cognome_cifrato + car;
cout<<"carattere "<<i<<" c in chiaro "<<cognome_chiaro[i]<<" chiave "<<chiave<<" cifrato "<<car<<" cognome incostruzione "<<cognome_cifrato<<endl;
}
setCognome(cognome_cifrato);
}
The two lines of code hghlighted have no effects.
|
|
|
|
|
Those lines have no effect because the default in C++ is to pass an argument by value. That is, to make a copy of it. If you want to modify the data that is passed to the function, it must be passed by reference; another option is to pass a pointer to the argument. To pass by reference, you append a & to the argument's type. So, you need to change your two small functions like this:
void anagrafica::setNome(string& n_)
{
nome_cifrato=n_;
}
void anagrafica::setCognome(string& c_)
{
cognome_cifrato=c_;
}
modified 8-Sep-22 13:10pm.
|
|
|
|
|
That will not make any difference. I have just tested the code and those methods both do what they are supposed to. The issue is more complex due to the confused (and confusing) nature of this code.
|
|
|
|