错误C2664:'int LSexecuteScriptLng(void *,const char *)

时间:2015-09-21 13:16:25

标签: visual-c++

// 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;
}

我需要帮助来解决以下问题:

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

错误消息为:

  

错误C2664:'int LSexecuteScriptLng(void *,const char )':不能   将参数2从'LPCTSTR'转换为'const char

请帮帮我。

2 个答案:

答案 0 :(得分:0)

它只是表示所说的内容:您不能将2字节字符转换为单字节字符。您需要声明并使用所有char个变量。由于您的项目设置设置为Unicode,TCHAR将映射到charCString也会映射到CStringW。你有选择:

  • 将所有需要的变量声明为char(或char的派生,例如CStringA
  • (不建议)是将项目设置更改为使用多字节。
  • 不要强行输入它。这就像迫使float*int* - 不会工作!

请参阅this article

答案 1 :(得分:-1)

错误消息中显示的函数记录在其帮助文档的LINGO DLL函数部分中。功能

&#34; int LSexecuteScriptLng(pLSenvLINGO pL,char * pcScript)&#34;

接受2个参数,第二个参数是指向字符串的指针。您应该使用以下内容定义字符串: char csScript [256];

然后在你的Lingo函数中使用它:

nError = LSexecuteScriptLng(pLINGO,csScript);