|
Cant use it, I asked the Microsoft MPI guys, and MSMPI only targets Windows. So in order to use MPI on Linux machines, you have to use some other MPI implementation, like Open MPI or Intel MPI.
|
|
|
|
|
I guess the easy way then is don't cross it ... compile it under a linux distro.
Is there any specific reason you wanted to cross it from Visual Studio?
In vino veritas
|
|
|
|
|
I want to be able to use the same MPI C++ code from both Windows and Linux, as it would effectively cut development time in half (its a rather complicated project).
|
|
|
|
|
Hi,
I've never done this. However I don't see any reason for this not to work.
Try following the instructions here using gendef and dlltool for generating the Linux shared lib with the MinGW-w64 Cross-Compiler.
TUTORIAL: Adapting MS-MPI for MinGW64[^]
Ignore the fact that the tutorial is for GFortran. The lib portion of the tutorial is what you need.
I am almost positive this should work... allowing you to have a single code base that compiles for both Windows and Linux.
Best Wishes,
-David Delaune
|
|
|
|
|
If I read you correctly I can configure VS2017 using MinGW-w64 as the compiler instead of g++?
|
|
|
|
|
Yes.[^]
If you spend some time setting this up... you will also only need 1 workstation to do the entire project. You can run your Linux binary on Windows Linux Subsystem.
Install the Linux Subsystem on Windows 10 | Microsoft Docs[^]
Spending 1/2 days setting this up may save you weeks in the long run... you can avoid multiple OS installations... multiple compilers... and do all your work in Visual Studio on Windows.
Best Wishes,
-HAL 9000
|
|
|
|
|
#include <iostream>
#include <cstring>
using namespace std;
class st{
char *p;
int len;
public:
st(){len=0; p=0;}
st(const char *s);
st(const st &s);
~st(){delete p;}
friend st operator + (const st &, const st &);
friend int operator <= (const st &, const st &);
friend void show(const st);
};
st :: st(const char *s){
len = strlen(s);
p = new char[len+1];
strcpy(p, s);
}
st :: st(const st &s){
len = s.len;
p = new char[len+1];
strcpy(p, s.p);
}
st operator + (const st &s, const st &t){
st temp;
temp.len = s.len + t.len;
temp.p = new char[temp.len + 1];
strcpy(temp.p, s.p);
strcat(temp.p, t.p);
return(temp);
}
int operator <= (const st &s, const st &t){
int m = strlen(s.p);
int n = strlen(t.p);
if(m <= n) return(1);
else return(0);
}
void show(const st s){
cout<<s.p;
}
int main(){
st s1 = "New ";
st s2 = "York";
st s3 = "Delhi";
st string1, string2, string3;
string1 = s1;
string2 = s2;
string3 = s3+s1;
cout<<"\nstring1 = "; show(string1);
cout<<"\nstring2 = "; show(string2);
cout<<endl;
cout<<"\nstring3 = "; show(string3);
cout<<"\n\n";
if(string1 <= string2){
show(string1); cout<<" smaller than "; show(string2);
cout<<endl;
}else {
show(string2); cout<<" smaller than "; show(string2);
cout<<endl;
}
return 0;
}
This program works fine when i replace
Quote: st string1, string2, string3;
with
Quote: st string1=s1, string2=s2, string3=s1+s3;
so what's the problem, i learned in class that we can pass the values in the constructor by calling it explicitly, and (string1, string2, string3) & (s1, s2, s3) have same return type i.e.class st.
So why isn't it working ?
thank you
|
|
|
|
|
To make this part of code working:
st string1, string2, string3;
string1 = s1;
string2 = s2;
you must implement the assignment operator for your class st.
|
|
|
|
|
As Victor Nijegorodov noted, your code violates the rule of three[^]: you have to define the assignment operator.
|
|
|
|
|
Hi Everyone.
I'm new to the site and new to C++. I'm coming from a background in VB and database admin.
I've got a console app which is trying to connect to an MS Access database and I'm having a terrible time trying to make this happen. All I'm trying to do here is execute a simple SQL SELECT statement and have the results come back.
The code below compiles just fine and runs fine but it keeps telling me it can't connect to the data source. I'm using VS 2017 and I've been able to set up a data connection which tests successfully every time. I've done my best to make sure I have all the correct drivers and other connection dlls. I'm a bit confused as to how I can have a successful connection within the VS environment (meaning I can browse tables, make queries, etc in VS) but I can't connect in my code. I've tried to copy and paste the 'build connection string' when I built the data connection and I also tried to reference the connection by name and no luck so far.
Thanks for your help!
Brennan
#include "stdafx.h"
#include<iostream>
#include <Windows.h>
#include <sql.h>
#include <sqltypes.h>
#include <sqlext.h>
#include <comutil.h>
#include <winerror.h>
SQLCHAR* dsnName = (SQLCHAR*)"Driver={Microsoft Access Driver (*.mdb, *.accdb)};dbq=C:\Program Files\MyTrading\DTP\DTP_DB.accdb;defaultdir=C:\Program Files\MyTrading\DTP;driverid=25;fil=MS Access;filedsn=C:\Program Files\MyTrading\DTP\DTP_DB.accdb.dsn;maxbuffersize=2048;maxscanrows=8;pagetimeout=5;safetransactions=0;threads=3;uid=admin;usercommitsync=Yes";
#define db "C:\\Program Files\\MyTrading\\DTP\\DTP_DB.accdb"
using namespace std;
int main()
{
const char* DAM = "Direct ODBC";
HENV hEnv;
HDBC hDbc;
RETCODE rc;
int iConnStrLength2Ptr;
char szConnStrOut[256];
SQLWCHAR* strSQL = (SQLWCHAR*)"SELECT Exchanges.[X Name], Exchanges.[X Full Name] FROM Exchanges;";
SQLCHAR chval1[128], chval2[128];
SQLWCHAR colName[128];
int ret1;
int ret2;
SQLINTEGER rowCount = 0;
SQLSMALLINT fieldCount = 0, currentField = 0;
HSTMT hStmt;
rc = SQLAllocEnv(&hEnv);
rc = SQLAllocConnect(hEnv, &hDbc);
rc = SQLDriverConnect(hDbc, NULL, (wchar_t*)dsnName, SQL_NTS, (wchar_t*)szConnStrOut, 255, (SQLSMALLINT*)&iConnStrLength2Ptr, SQL_DRIVER_NOPROMPT);
if (SQL_SUCCEEDED(rc))
{
printf("%s: Successfully connected to database. Data Source Name: \n %s\n",
DAM, szConnStrOut);
printf("%s: SQL query:\n %s\n", DAM, strSQL);
rc = SQLAllocStmt(hDbc, &hStmt);
rc = SQLPrepare(hStmt, strSQL, SQL_NTS);
rc = SQLBindCol(hStmt, 1, SQL_C_CHAR, chval1, 128, (SQLLEN*)&ret1);
rc = SQLBindCol(hStmt, 2, SQL_C_CHAR, chval2, 128, (SQLLEN*)&ret2);
rc = SQLExecute(hStmt);
if(SQL_SUCCEEDED(rc))
{
printf("%s: Retrieve schema info for the given result set :\n", DAM);
SQLNumResultCols(hStmt, &fieldCount);
if (fieldCount > 0)
{
for (currentField = 1; currentField <= fieldCount; currentField++)
{
SQLDescribeCol(hStmt, currentField, colName, sizeof(colName), 0, 0, 0, 0, 0);
printf(" | %s", colName);
}
printf("\n");
}
else
{
printf("%s: Error: Number of fields in the result set is 0.\n", DAM);
}
printf("%s: Fetch the actual data:\n", DAM);
rc = SQLFetch(hStmt);
while (SQL_SUCCEEDED(rc))
{
printf(" \ %s | %s\n", chval1, chval2);
rc = SQLFetch(hStmt);
rowCount++;
};
printf("%s: Total Row Count: %d\n", DAM, rowCount);
rc = SQLFreeStmt(hStmt, SQL_DROP);
}
}
else
{
printf("%s: Couldn't connect to %s.\n", DAM, dsnName);
}
SQLDisconnect(hDbc);
SQLFreeHandle(SQL_HANDLE_DBC, hDbc);
SQLFreeHandle(SQL_HANDLE_ENV, hEnv);
printf("%s: Cleanup. Done.\n", DAM);
return 0;
}
|
|
|
|
|
Any particular reason you chose to start with c++?
C# and VB.Net will provide a lot more examples of what you're after; particularly when it comes to Access.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Can you use MFC?
With CDatabase and CRecordset classes your DB access would be more easy and simple!
|
|
|
|
|
Don't recommend MFC for new developments the framework is going to become increasingly problematic now it's out of support and cracks have already opened up with current updates of Windows 10.
If you really feel it would be good to use at least make them aware of the issue going forward.
In vino veritas
modified 15-Mar-18 23:20pm.
|
|
|
|
|
AFAIK is MFC not out of support. It is not enhanced anymore but bugs are (and will be probably) fixed.
But I can understand your suggestion to use it not for new projects.
From your (very good) answer to the initial question:
Quote: There is a class in C++ that acts much like VB strings called CString
CString is a MFC class and requires linking with the MFC libraries.
|
|
|
|
|
leon de boer wrote: Don't recommend MFC for new developments the framework is going to become increasingly problematic now it's out of support and cracks have already opened up with current updates of Windows 10.
And where did you get this information from? Some "very secure source" from MSFT? Or?
|
|
|
|
|
If you don't believe me then stop being lazy and ask on the microsoft forums, if you have a MSDN subscription go to support and see what it says.
The MFC source has been released & open sourced which gives you a clear indication of the commercial value, it comes free with Visual Studio 17 community edition.
You are still on version 14 and have been since 20 July 2015 and they managed the small update to deal with the Windows 10 issues which managed to get released with the last Visual Studio 17 update cycle on 6 March 2018. The update simply deals with legacy MFC calls that stopped working.
MFC is targetted to the legacy bridge path it will have no native access to the ever expanding Windows 10 API
Calling Windows 10 APIs From a Desktop Application - Windows Developer BlogWindows Developer Blog[^]
I should mention the old Win16 API still exist in windows 10 under much the same support and there are a lot of legacy programs that still work and there are also a lot that don't. I love the old 16bit API, I cut my teeth on it but I wouldn't recommend someone write a new development targeting it.
So we get into some tricky language about what is and what does support actually mean. I loved the above quote in the article
Or put a different way, there are no secret APIs being kept away from Windows developers.
We could put that another way, we have told you the API and we have no intention of adding it MFC but you can.
I will leave you to ponder thru all that and decide if I got it all wrong. I am not microsoft and I don't speak for them so ask them directly. As far as I know your old code will hopefully continue to work on Windows but you will have no access to the new features unless you write them yourself.
In vino veritas
modified 18-Mar-18 20:59pm.
|
|
|
|
|
Put a debug point jsut after this line and look at string
Quote: SQLWCHAR* strSQL = (SQLWCHAR*)"SELECT Exchanges.[X Name], Exchanges.[X Full Name] FROM Exchanges;";
I am betting it comes out as garbage
Why... this code sequence below is a text string of char AKA 8 bits
Quote: "SELECT Exchanges.[X Name], Exchanges.[X Full Name] FROM Exchanges;"
I am betting that SQLWCHAR is a wide character AKA something that isn't 8 bits and you just forcibly typecast it.
I am guessing you have to forcibly typecast it because the compiler objected to you assigning it.
You need to do a quick update reading on how to write wide and unicode strings in C/C++
Working with Strings (Windows)[^]
I am guessing that text needed to be .. the L at the start is very important
Quote: L"SELECT Exchanges.[X Name], Exchanges.[X Full Name] FROM Exchanges;"
Coming off VB you will have an issue that C++ won't hold your hand, strings are not held in both formats like they are in VB because it's slow and costs time and space. VB looks at which of the various forms it matches and will use that right one. There is a class in C++ that acts much like VB strings called CString which carries the strings in both form if you need training wheels, you could use it.
The other option is to become familar with #include <tchar.h> and the features it offers but don't mix it with CStrings if you go that path.
There are other bits that look suspiciously like you have forced typecast probably to get over a compiler error
I am looking at =====> (wchar_t*)dsnName
Go thru and work out what needs to be char and what needs to be wchar and write the constant strings in the correct form
In vino veritas
modified 15-Mar-18 23:19pm.
|
|
|
|
|
Thanks very much for the help everyone.
One of the main reasons for using C++ in this case is the amount of realtime calculations that are designed into the app.
You're totally right about the strings!! The first thing I tried to do in C++ was get it to print 'Hello World' to the console window and I could figure out why that could be so bloody hard to do. Anyway, thanks for suggesting tchar.h. I will definitely spend some time with that. One of the more challenging things for me so far is just trying to find the library to be looking at.
We had considered going the MFC route but we're saving that as a last resort because it seemed very bloated. Thanks for the lack of support warning. Didn't know that.
Well, I did finally get it going with OLE DB. So well do some more testing and playing around with it but I think we're on our way.
Thanks for your help guy!!!
|
|
|
|
|
Have you single-stepped through the code using the debugger? What is the value of rc along the way?
"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
|
|
|
|
|
#include <iostream>
using namespace std;
const int size = 3;
class vector{
int v[size];
public:
vector();
vector(int *x);
friend vector operator * (int a, vector b);
friend vector operator * (vector b, int a);
friend istream & operator >> (istream &, vector &);
friend ostream & operator << (ostream &, vector &);
};
in the above code the i am having problem understanding the friend f^n Quote: friend istream & operator >> (istream &, vector &);
here's what i know, so istream is for input streaming of data & ostream for output, and does & epresents some kind of reference to function >> ?
It is really confusing, please explain.
Thank you.
|
|
|
|
|
friend istream & operator >> (istream &, vector &);
That is just for telling the computer the extraction operator (>> ) is friend of the vector class.
The reference (& ) is part of the extraction operator signature, e.g.
istream & operator >> (istream & is, vector & v);
Because such a operator
- takes a reference to
istream and a reference to a vector as arguments. - returns a reference to a
istream . Incidentally this the magic underneath the extraction operator chaining, for instance:
cin >> v >> i; ->
(cin >> v) >> i; ->
cin >> i; ->
cin;
|
|
|
|
|
Hi
I have a class which derives from CScrollView and i have a message map in it whose base class is CScrollView as follows:
class MyClass : public CScrollView
{
public :
DECLARE_MESSAGE_MAP();
void OnButtonSelect();
void Init();
CButton m_button;
}
BEGIN_MESSAGE_MAP(MyClass , CScrollView)
ON_COMMAND(ID_FILE_PRINT, OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, OnFilePrintPreview)
ON_BN_CLICKED(1010, OnButtonSelect)
END_MESSAGE_MAP()
MyClass::Init()
{
m_button.Create(_T("Hi"),, BS_PUSHBUTTON, CRect(0, 0, 80, 20), m_cdRadViewer, 1010);
m_button.ShowWindow(SW_SHOW);
}
MyClass:OnButtonSelect()
{
AfxMessageBox(_T("hi, button Clicked"));
}
In the above code, when i click on button, OnButtonSelect() is not getting called even i added the button notification message in Message Map. After investigation i understood, the Base class mentioned in Message map and my class is from CScrollView and it cannot inherit the button features.
If this is true, how can i access the button message in my function.
I want to create the buttons in runtime and want to do some operation based on the button click.
Is it possible to notify in case if my class is derived from CScrollView?
modified 15-Mar-18 5:40am.
|
|
|
|
|
In DECLARE_MESSAGE_MAP you have:
void OnButtonSelect();
but in BEGIN_MESSAGE_MAP you have:
ON_BN_CLICKED(1010, OnMyButtonClicked)
which is not defined.
|
|
|
|
|
Sorry its typo. The same function available in .h and .cpp. I corrected it now.
But still not working.
modified 15-Mar-18 6:01am.
|
|
|
|
|
You are setting the parent of your button to the m_cdRadViewer window. Then that window will receive the BN_CLICKED notfication instead of your MyClass instance window.
You have to pass the correct window:
m_button.Create(_T("Hi"), BS_PUSHBUTTON, CRect(0, 0, 80, 20), this, 1010); Note that I have also removed an additional comma which would make your code throw a compilation error.
|
|
|
|
|