Visual c++ 错误C2664:&x27;int LSexecuteScriptLng(无效*,常量字符*)

Visual c++ 错误C2664:&x27;int LSexecuteScriptLng(无效*,常量字符*),visual-c++,Visual C++,错误信息为: 错误C2664:'int LSexecuteScriptLng(void*,const char)':无法 将参数2从“LPCTSTR”转换为“const char” 请帮助我。错误消息中显示的函数记录在其帮助文档的DLL函数部分。功能 int LSexecuteScriptLng(pLSenvLINGO pL,char*pcScript) 接受2个参数,第二个参数是指向字符串的指针。您应该使用以下内容定义字符串: char-csScript[256] 然后在你的行话功能中使用它:

错误信息为:

错误C2664:'int LSexecuteScriptLng(void*,const char)':无法 将参数2从“LPCTSTR”转换为“const char”


请帮助我。

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

int LSexecuteScriptLng(pLSenvLINGO pL,char*pcScript)

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

然后在你的行话功能中使用它:


错误=LSexecuteScriptLng(pLINGO,csScript)

它的意思是:不能将2字节字符转换为1字节字符。您需要声明并使用所有
char
变量。由于项目设置设置为Unicode,
TCHAR
将映射到
char
,并且
CString
将映射到
CStringW
。您可以选择:

  • 将所有需要的变量声明为
    char
    (或
    char
    的派生,例如
    CStringA
  • (不建议)将项目设置更改为使用多字节
  • 永远不要强制键入和投射它。这就像强制一个
    float*
    int*
    -不起作用

请参见

csScript
声明为
CStringA
(A表示ASCII,而不是Unicode),将所有
L
s放在字符串文本前面,如
csScript=“SET ECHOIN 1\n”,并在
LSexecuteScriptLng
调用中,强制转换为
LPCSTR
(注意编号T)。函数需要ASCII字符串,而不是Unicode字符串。
// 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);