// Salam001Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "Salam001.h"
#include "Salam001Dlg.h"
#include "DlgProxy.h"
#include "afxdialogex.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CSalam001Dlg dialog
IMPLEMENT_DYNAMIC(CSalam001Dlg, CDialogEx);
CSalam001Dlg::CSalam001Dlg(CWnd* pParent /*=NULL*/)
: CDialogEx(CSalam001Dlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_pAutoProxy = NULL;
}
CSalam001Dlg::~CSalam001Dlg()
{
// If there is an automation proxy for this dialog, set
// its back pointer to this dialog to NULL, so it knows
// the dialog has been deleted.
if (m_pAutoProxy != NULL)
m_pAutoProxy->m_pDialog = NULL;
}
void CSalam001Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CSalam001Dlg, CDialogEx)
ON_WM_CLOSE()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
END_MESSAGE_MAP()
// CSalam001Dlg message handlers
BOOL CSalam001Dlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CSalam001Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialogEx::OnPaint();
}
}
// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CSalam001Dlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
// Automation servers should not exit when a user closes the UI
// if a controller still holds on to one of its objects. These
// message handlers make sure that if the proxy is still in use,
// then the UI is hidden but the dialog remains around if it
// is dismissed.
void CSalam001Dlg::OnClose()
{
if (CanExit())
CDialogEx::OnClose();
}
void CSalam001Dlg::OnOK()
{//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int nError, nPointersNow;
double dStatus, dn_Mu, dSol_Inv, dSol_Rot;
CString csScript, cs;
// Get user's staffing requirements from our dialog box
//UpdateData();
// Load staffing requirements into the LINGO transfer array.
// LINGO uses double precision for all values.
dn_Mu = 5.0;
//n_Mu[0] = (double)n_Mu;
// create the LINGO environment object
pLSenvLINGO pLINGO;
pLINGO = LScreateEnvLng();
if (!pLINGO)
{
AfxMessageBox(_T("Unable to create LINGO Environment"));
return;
}
// Open LINGO's log file
nError = LSopenLogFileLng(pLINGO, "C:\\LINGO8\\LINGO.log");
if (nError) goto ErrorExit;
// Pass memory transfer pointers to LINGO
// @POINTER(1)
nError = LSsetPointerLng(pLINGO, &dn_Mu, &nPointersNow);
if (nError) goto ErrorExit;
// @POINTER(2)
nError = LSsetPointerLng(pLINGO, &dSol_Inv, &nPointersNow);
if (nError) goto ErrorExit;
// @POINTER(3)
/* nError = LSsetPointerLng(pLINGO, &dSol_Rot, &nPointersNow);
if (nError) goto ErrorExit;
*/
// @POINTER(3)
nError = LSsetPointerLng(pLINGO, &dStatus, &nPointersNow);
if (nError) goto ErrorExit;
// Here is the script we want LINGO to run
csScript = L"SET ECHOIN 1\n";
csScript = csScript + L"TAKE \\Salam002\\LINGO1-3.LNG\n" ;
csScript = csScript + L"GO\n";
csScript = csScript + L"QUIT\n";
// Run the script
dStatus = -1.e0;
nError = LSexecuteScriptLng(pLINGO, ( LPCTSTR ) csScript);
// Close the log file
LScloseLogFileLng(pLINGO);
// Any problems?
if (nError || dStatus)
{
// Had a problem
AfxMessageBox( _T("Unable to solve!"));
}
else {
// Everything went ok ... load results into the dialog box
// m_csStartMon.Format("%d", (int)dStart[0]);
UpdateData(FALSE);
}
goto Exit;
ErrorExit:
cs.Format(_T("LINGO Errorcode: %d"), nError);
AfxMessageBox(cs);
return;
Exit:
LSdeleteEnvLng(pLINGO);
/////////////////////////////////////////////////////////////////////////////////////////////////////////
}
void CSalam001Dlg::OnCancel()
{
if (CanExit())
CDialogEx::OnCancel();
}
BOOL CSalam001Dlg::CanExit()
{
// If the proxy object is still around, then the automation
// controller is still holding on to this application. Leave
// the dialog around, but hide its UI.
if (m_pAutoProxy != NULL)
{
ShowWindow(SW_HIDE);
return FALSE;
}
return TRUE;
}
I need help to fix the problem in the following line :
nError = LSexecuteScriptLng(pLINGO, ( LPCTSTR ) csScript);
the error message is :
error C2664: 'int LSexecuteScriptLng(void *,const char )' : cannot convert argument 2 from 'LPCTSTR' to 'const char
Please help me.
csScript
asCStringA
(A for ASCII, as opposed to Unicode), drop allL
s in front of string literals, as incsScript = "SET ECHOIN 1\n";
, and inLSexecuteScriptLng
call, cast toLPCSTR
(note no T). The function wants an ASCII string, not a Unicode string. – Igor Tandetnik