Newing a derived class to create a default object
I have a base class which has several derived classes. Within the derived class I have an enum which tells me which derived class the object belongs to. Now, I want a function create a new object of a derived class, and the only parameter I'd pass would be the enum value of the class I want to create.
I can easily make a function which does a case/switch on the enum and does the appropriate new, but I was wondering if there is a better/more elegant/different way of doing it...?
Getting compilation errors after upgraded a C++ project from VS2013 to VS2017 RC
I converted a midsize C++ project (little less than 2 million lines of code) from VS2013 to VS2017 RC. The conversion went successfully, but when I attempted to compile, I got the following errors:
[code]1>------ Build started: Project: abcd, Configuration: Debug Win32 ------
1>StdAfx.cpp
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\type_traits(1534): error C2760: syntax error: expected ')' not ','
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\type_traits(1825): error C2760: syntax error: expected ')' not ','
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\type_traits(1834): note: see reference to class template instantiation 'std::reference_wrapper<_Ty>' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\type_traits(1944): error C2760: syntax error: expected ')' not ','
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\xmemory0(528): error C2760: syntax error: expected ')' not ','
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\xmemory0(563): error C2760: syntax error: expected ')' not ','
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\xmemory0(641): error C2760: syntax error: expected ')' not 'identifier'
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\xstring(3623): warning C4467: usage of ATL attributes is deprecated
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\stdexcept(22): note: see reference to class template instantiation 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\xstring(3623): error C2337: '[': attribute not found
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\xstring(3623): error C2146: syntax error: missing ']' before identifier 'noreturn'
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\xstring(3623): error C2143: syntax error: missing ';' before ']'
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\xstring(3623): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\xstring(3624): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\xstring(3644): error C2337: '[': attribute not found
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\xstring(3644): error C2146: syntax error: missing ']' before identifier 'noreturn'
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\xstring(3644): error C2143: syntax error: missing ';' before ']'
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\xstring(3644): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\xstring(3645): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\functional(34): error C2760: syntax error: expected ')' not ','
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\functional(38): note: see reference to class template instantiation 'std::_Mem_fn<_Memptr>' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\functional(763): error C2760: syntax error: expected ')' not ','
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\functional(769): note: see reference to class template instantiation 'std::_Select_fixer<_Cv_TiD,false,true,0>' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\functional(798): error C2760: syntax error: expected ')' not ','
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\functional(813): error C2760: syntax error: expected ')' not ','
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\functional(871): error C2760: syntax error: expected ')' not ','
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\functional(873): note: see reference to class template instantiation 'std::_Binder<_Ret,_Fx,_Types...>' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\vector(1960): error C2146: syntax error: missing ']' before identifier 'noreturn'
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\vector(1960): error C2143: syntax error: missing ';' before ']'
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\vector(1960): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\vector(1961): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\vector(1965): error C2337: '[': attribute not found
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\vector(1965): error C2146: syntax error: missing ']' before identifier 'noreturn'
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\vector(1965): error C2143: syntax error: missing ';' before ']'
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\vector(1965): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.10.24930\include\vector(1966): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>Done building project "abcd.vcxproj" -- FAILED.[/code]
Could you recommend how to find the reason of the errors?
The hard part is that all errors are in VS header files. I have not been able to turn more verbose output to get more details.
Thank you!
How to save data from checkedlistbox to access database?
Hello. I'm having trouble with inserting data to a database based on items checked on a checkedlistbox. There are two and the data on the checkedlistboxes are also from the same database but from different tables and they will serve as foreign keys to the table where I need to save them. I need it so that when the user finishes selecting the items and click the button, it would instantly save it to the database. Here is the code that I use to get the data from the database for both checkedlistboxes:
[code]Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Using connection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\rose&mike\Desktop\DbSysDel3\salondbaccess.accdb"),
adapter As New OleDbDataAdapter("SELECT Service_Name, Service_Fee FROM [Service_Types]", connection)
Dim sql As String = "Select Lastname FROM Employees2"
Dim cmd As New OleDbCommand
cmd = New OleDb.OleDbCommand(sql, connection)
connection.Open()
Dim dr As OleDbDataReader = cmd.ExecuteReader
If dr.HasRows Then
While dr.Read
chcklstbx2.Items.Add(dr(0))
End While
End If
Dim table As New DataTable
adapter.Fill(table)
With chcklstbx1
.DataSource = table
.DisplayMember = "Service_Name"
.ValueMember = "Service_Fee"
End With
connection.Close()
End Using
End Sub[/code]
WebClient gives empty response?
Hello,
I wonder why I get an empty response from the below URL?
When open the URL in chrome, there is a JSON response.
[code]WebClient client = new WebClient();
client.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2");
Stream data = client.OpenRead("https://api.coinsecure.in/v1/exchange/ticker");
StreamReader reader = new StreamReader(data);
String responseBody = reader.ReadToEnd();
data.Close(); reader.Close();
MessageBox.Show(responseBody);[/code]
amp synchronize() crash
how to change array_view to array for this code
[code]void Zoom(Picture *source, Picture *destination)
{
int rows = destination->Rows;
int cols = destination->Cols;
int centerx = source->CenterX;
int centery = source->CenterY;
int radius = source->Radius;
float xrate = (float)rows / (float)radius / 2;
float yrate = (float)cols / (float)radius / 2;
unsigned int * src = (unsigned int *)source->Data;
unsigned int *dest = (unsigned int *)destination->Data;
array_view<const unsigned int, 2> SV(source->Rows,source->Cols,src);
array_view<unsigned int, 2> DV(rows,cols,dest);
DV.discard_data();
parallel_for_each(DV.extent, [=](index<2> idx) restrict(amp)
{
int x = idx[0], y = idx[1];
int xx = x / xrate + centerx - radius;
int yy = y / yrate + centery - radius;
DV[idx] = SV(xx,yy);
});
DV.synchronize();
concurrency::amp_uninitialize();
}[/code]
thumbnailPhoto not getting in case of Global Catalog
I have created a AD forest that search for a user across all domains in the forest using its global catalog connection string.
I am trying to get thumbnailPhoto of AD user using c# code. But I did not get thumbnailPhoto property in result object even though it exist in AD.
I had verified the thumbnailPhoto prop in AD using powershell. Also I have verified it by getting using LDAP connection string. It both case I got the byte array.
Below is the code to get user and its properties and _configuration.GlobalCatalog returns the Global catalog connections string which is in format (GC://domain-name).
[code]public Task<ProfileImage> GetProfileImageByEmail(string email)
{
var filterQuery = ("mail=" + email);
return Task.FromResult(GetProfileImageFromAD(filterQuery));
}
private ProfileImage GetProfileImageFromAD(string filterQuery)
{
var result = GetADUserDetails(filterQuery);
if (result == null)
return null;
if (result.Properties.Contains("thumbnailPhoto"))
{
var imageBytes = result.Properties["thumbnailPhoto"][0] as byte[];
if (imageBytes != null)
{
return new ProfileImage
{
Content = new MemoryStream(imageBytes),
ContentType = "image/jpeg"
};
}
}
return null;
}
private SearchResult GetADUserDetails(string filterQuery)
{
using (var userBinding = new DirectoryEntry(_configuration.GlobalCatalog))
{
using (DirectorySearcher adSearch = new DirectorySearcher(userBinding))
{
adSearch.ReferralChasing = ReferralChasingOption.All;
adSearch.Filter = filterQuery;
adSearch.PropertiesToLoad.Add("mail");
adSearch.PropertiesToLoad.Add("sn");
adSearch.PropertiesToLoad.Add("givenName");
adSearch.PropertiesToLoad.Add("thumbnailPhoto");
return adSearch.FindOne();
}
}
}[/code]
WebBrowser Point Zoom
Hello, im using click.point to click in webbrowser control.
I've added zoom out (i need it for i can see all elements) my problem is if i keep the zoom at 100 works fine if i put zoom to 25 dont work.
Zoom code:
[code]Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As EventArgs) Handles WebBrowser1.DocumentCompleted
Try
Dim Res As Object = Nothing
Dim MyWeb As Object
MyWeb = Me.WebBrowser1.ActiveXInstance
MyWeb.ExecWB(Exec.OLECMDID_OPTICAL_ZOOM, ExecOpt.OLECMDEXECOPT_DONTPROMPTUSER, 25, IntPtr.Zero)
Catch ex As Exception
MsgBox("Error:" & ex.Message)
End Try
End Sub[/code]
Im getting point position with this:
[code] Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim WebLoc As Point = PointToScreen(WebBrowser1.Location)
Dim WebCurPos As Point = New Point(Cursor.Position.X - WebLoc.X, Cursor.Position.Y - WebLoc.Y)
With WebCurPos
If .X < 0 Or .Y < 0 Or .X > WebBrowser1.Width Or .Y > WebBrowser1.Height Then
'Debug.WriteLine("Mouse position outside of webbrowser!")
Else
Label1.Text = (WebCurPos.ToString)
End If
End With
End Sub[/code]
If i use zoom code to reduce to 25 the click not work if i use it with 100 works.
I think i need to divide my code of getting point but i dont know how.
PrintPreviewDialog
On the following page,
[img]
https://social.msdn.microsoft.com/Forums/getfile/1011324[/img]
How can I fix this error on this page?
my code;
[code] private void btnPrint_Click(object _sender, EventArgs args)
{
PrintPreviewDialog ppd = new PrintPreviewDialog();
ppd.Document = printdocument;
ppd.ClientSize = new Size(900, 600);
ppd.ShowIcon = true;
ppd.Icon = new Icon(Assembly.GetEntryAssembly().GetManifestResourceStream("Konak.Desktop.Images.SBCM.ICO"));
ppd.StartPosition = FormStartPosition.CenterScreen;
ppd.Document.DocumentName = "Transfer Islem Bilgileri";
this.printdocument.PrintPage += (s, a) => { printdocument_PrintPage(s, a); };
ppd.ShowDialog();
}
private void printdocument_PrintPage(object S, PrintPageEventArgs a)
{
float leftMargin = a.MarginBounds.Left;
float topMargin = a.MarginBounds.Top;
int count = 0;
List<string> lst = new List<string>();
for (int i = 0; i < listboxInfoList.Items.Count; i++)
{
a.Graphics.DrawString(listboxInfoList.Items[i].ToString(), this.Font, Brushes.Black, leftMargin, topMargin + count * this.Font.GetHeight(a.Graphics), new StringFormat());
lst.Add(listboxInfoList.Items[i].ToString());
count++;
}
if (!(count >= lst.Count - 1))
{
a.HasMorePages = true;
}
else
{
a.HasMorePages = false;
}
}[/code]
When I try to set Active Directory user properties, throw exception
It`s a good day to die....
I`m trying to make & modify windows application about AD group and users.
This application works like this.
Users choose property and mapping it from source data(DB or Excel files...)
And press sync start button, that properties put into the AD User.
But When I set AD user`s properties, it throws exception like this in DirectoryEntry.CommitChanges(); block.
The directory
service cannot perform the requested operation on the RDN attribute of an object.
Sadly I`m a newbie of Active Directory, I don`t know how to solve it... Please help me.
Code is below.
[code]void CreateADUser(string ppk,string pk,DataRow row)
{
string pass = GetPass(pk,row,LogSections.AD);
DirectoryEntry addept = adm.FindOU(ppk);
string sOU = adm.GetPrincipalPath(addept);
var aduser = adm.CreateNewUser(sOU, pk, pass, pk, null, null, adm.sDomain);
SetAdUserProperties(pk, pass, row);
MoveUser(ppk,pk);
}
void SetAdUserProperties(string pk,string pass,DataRow row)
{
if (row == null) return;
List<ADMapping> MappingPatterns = GetAdMappings(Words.User,false);
var colnames = Tool.GetColNames(row);
var aduser = adm.GetUser(pk);
var de=aduser.GetUnderlyingObject() as DirectoryEntry;
foreach (var ADMap in MappingPatterns)
{
string val = ADMap.Mapping;
val=Util.ReplaceColPattern(val, row);
SetProperty(de, ADMap.CN, val);
}
if (!string.IsNullOrWhiteSpace(pass))
{
var UserPkColumn = AppConfigHelper.GetAppString(Words.SourceUserPKColumn);
UserPkColumn = Util.GetActualColName(UserPkColumn);
aduser.SetPassword(pass);
QueryHelper.Update(QueryHelper.ConnectionString, Words.ShadowUserTable
,new SqlParameter[] { new SqlParameter("@passwd", pass) }
, new SqlParameter("@"+UserPkColumn,pk));
}
aduser.Save();
}
public void SetProperty(DirectoryEntry oDE, string sPropertyName, object sPropertyValue)
{
if (sPropertyValue != null && !string.IsNullOrWhiteSpace(sPropertyValue.ToString()))
{
if (oDE.Properties.Contains(sPropertyName))
{
oDE.Properties[sPropertyName].Value = sPropertyValue;
}
else
{
oDE.Properties[sPropertyName].Add(sPropertyValue);
}
try
{
oDE.CommitChanges(); //exception here.
oDE.Close();
}
catch (Exception)
{
}
}
}[/code]