2015-09-21 65 views
1
// 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; 
} 

我需要幫助解決以下行的問題:錯誤C2664:「詮釋LSexecuteScriptLng(void *的,爲const char *)

nError = LSexecuteScriptLng(pLINGO, (LPCTSTR) csScript); 

錯誤消息是:

error C2664:'int LSexecuteScriptLng(void *,const char )':不能 將參數2從'LPCTSTR'轉換爲'const char

請幫幫我。

+0

申報'csScript'如'CStringA'(A爲ASCII,而不是爲Unicode),丟棄所有'L's在字符串的前面,如在'csScript =「SET ECHOIN 1 \ n「;',在'LSexecuteScriptLng'調用中,轉換爲'LPCSTR'(注意不是T)。該函數需要一個ASCII字符串,而不是一個Unicode字符串。 –

回答

-1

錯誤消息中顯示的函數記錄在其幫助文檔的LINGO DLL函數部分。功能

「INT LSexecuteScriptLng(pLSenvLINGO PL,字符* pcScript)」

需要兩個參數,與所述第二個是一個指針,指向字符串。你應該像這樣定義你的字符串: char csScript [256];

然後在行話功能使用它:

n錯誤= LSexecuteScriptLng(pLINGO,csScript);

0

它只是意味着說什麼:不能將2字節字符轉換爲單字節字符。您需要聲明並使用所有的變量char。由於您的項目設置設置爲Unicode,因此TCHAR將映射到char,並且CString也會映射到CStringW。您可以選擇:

  • 聲明所有需要的變量是char(或char推導,例如CStringA
  • (不建議)是更改項目設置使用多字節。
  • 不要永遠強制類型投它。它像強制float*int* - 不會工作!

參見this article

相關問題