Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error C2182 illegal use of type 'void' #358

Closed
sinall opened this issue Mar 15, 2015 · 6 comments
Closed

error C2182 illegal use of type 'void' #358

sinall opened this issue Mar 15, 2015 · 6 comments

Comments

@sinall
Copy link

sinall commented Mar 15, 2015

System

Windows XP + Microsoft SDKs v7.1 + Microsoft Visual Studio 10.0

.h file

#ifndef _WAPIWRAPPERCPP_H
#define _WAPIWRAPPERCPP_H

#include <windows.h>
#include <comutil.h>

#ifdef WAPIWRAPPERCPP_EXPORTS
#define WAPIWRAPPERCPP_EXP __declspec(dllexport)
#else
#define WAPIWRAPPERCPP_EXP __declspec(dllimport)
#endif

//�ؼ�δע�����
const LONG noRegErr = -1;

enum ErrMsgLang //������Ϣ����
{
    eENG = 0,   ///< Ӣ��
    eCHN,       ///< ����
};

class WAPIWRAPPERCPP_EXP WindData
{
public:
    VARIANT data;   ///< ����
    VARIANT codes;  ///< Code�б�
    VARIANT fields; ///< ָ���б�
    VARIANT times;  ///< ʱ���б�
    LONG errorCode; ///< ������
public:

    WindData();
    ~WindData();

    VOID InitWindData();
    VOID ClearWindData();

    //��ȡ������Ϣ
    LPCWSTR GetErrorMsg() const;

    //����ת������(��Ҫdelete)
    static WCHAR* DateToString(DATE date, LPCWSTR strFormat = L"%Y-%m-%d");
    static VOID FreeString(WCHAR*& pStr);

    //////////////////////////////////////////////////////////////////////////
    //����ʹ��

    INT GetCodesLength() const;
    INT GetFieldsLength() const;
    INT GetTimesLength() const;

    LPCWSTR GetCodeByIndex(int index) const;
    LPCWSTR GetFieldsByIndex(int index) const;
    BOOL GetTimeByIndex(int index, WCHAR timeBuffer[], int& length) const;
    DATE GetTimeByIndex(int index) const;

    //��ȡ���ݲ�ѯ�ӿ�OneData
    BOOL GetDataItem(int timeIndex, int codesIndex, int fieldsIndex, VARIANT& outItem) const;

    //��ȡ�����б�
    const DATE* GetTDaysInfo(LONG& lDateCount) const;

    //////////////////////////////////////////////////////////////////////////
    //����ʹ��

    INT GetRecordCount() const;

    //��ȡ���׽ӿ�OneData
    BOOL GetTradeItem(int recordIndex, int fieldsIndex, VARIANT& outItem) const;

    //��ȡ��¼ID
    LONG GetLogonID() const;

    //��ȡOrder����Id
    LONG GetOrderRequestID() const;

    //��ȡOrderNumber
    LPCWSTR GetOrderNumber(int recordIndex = 0) const;
};

// �ص���������
typedef LONG (WINAPI *WsqCallBack)(const WindData &windData);

// �����Ǵ� WAPIWrapperCpp.dll ������
class WAPIWRAPPERCPP_EXP CWAPIWrapperCpp {
public:

    //��������
    //////////////////////////////////////////////////////////////////////////
    //Wind�ӿ���������
    static LONG start(LPCWSTR options = NULL, LPCWSTR options2 = NULL, LONG timeout = 5000);

    //Wind�ӿ���ֹ����
    static LONG stop();

    //�ж�����״̬
    static LONG isconnected();

    //�� requestId Ϊ0 ȡ���������󣻷���ֻȡ������ID�ŵ�����
    static VOID cancelRequest(ULONGLONG requestId);

    //ȡ����������
    static VOID cancelAllRequest();

    //��ȡ��������Ӧ�Ĵ�����Ϣ
    static BOOL getErrorMsg(LONG errCode, ErrMsgLang lang, WCHAR msg[], int& /*inout*/msgLength);

    //////////////////////////////////////////////////////////////////////////

    //���ݺ���
    //////////////////////////////////////////////////////////////////////////
    //��ֵ����wsd�������������
    static LONG wsd(WindData& outWindData, LPCWSTR windCodes, LPCWSTR fields, LPCWSTR startTime = NULL, LPCWSTR endTime = NULL, LPCWSTR options = NULL);

    //��ֵ����wss�������ʷ����
    static LONG wss(WindData& outWindData, LPCWSTR windCodes, LPCWSTR fields, LPCWSTR options = NULL);

    //��ֵ����wsi����÷�������
    static LONG wsi(WindData& outWindData, LPCWSTR windCodes, LPCWSTR fields, LPCWSTR startTime, LPCWSTR endTime, LPCWSTR options = NULL);

    //��ֵ����wst�������������
    static LONG wst(WindData& outWindData, LPCWSTR windCodes, LPCWSTR fields, LPCWSTR startTime, LPCWSTR endTime, LPCWSTR options = NULL);

    //��ֵ����wsq�����ʵʱ����
    //�Ƕ���ģʽ��ȡһ���Կ�������
    static LONG wsq(WindData& outWindData, LPCWSTR windCodes, LPCWSTR fields, LPCWSTR options = NULL);

    //����ģʽ������ʵʱ���ݣ�����ͨ���ص���������
    static LONG wsq(ULONGLONG &reqId, LPCWSTR windCodes, LPCWSTR fields, WsqCallBack callBack, LPCWSTR options = NULL, BOOL updateAllFields = FALSE);

    //��ֵ����wset�����ָ�����ݼ�
    static LONG wset(WindData& outWindData, LPCWSTR reportName, LPCWSTR options = NULL);

    //��ֵ����edb����þ�������
    static LONG edb(WindData& outWindData, LPCWSTR windCodes, LPCWSTR startTime = NULL, LPCWSTR endTime = NULL, LPCWSTR options = NULL);

    //��ϱ�����
    static LONG wpf(WindData& outWindData, LPCWSTR portfolioName, LPCWSTR viewName, LPCWSTR options = NULL);

    //����ϴ�����
    static LONG wupf(WindData& outWindData, LPCWSTR portfolioName, LPCWSTR tradeDate, LPCWSTR windCodes, LPCWSTR quantity, LPCWSTR costPrice, LPCWSTR options = NULL);

    //֤��ɸѡ����
    static LONG weqs(WindData& outWindData, LPCWSTR planName, LPCWSTR options = NULL);

    //�����ա������ա������յ��������к���
    static LONG tdays(WindData& outWindData, LPCWSTR startTime, LPCWSTR endTime, LPCWSTR options = NULL);

    //�����ա������ա������յ�����ƫ�Ƽ���
    static LONG tdaysoffset(DATE& outDate, LPCWSTR startTime, LONG offset, LPCWSTR options = NULL);

    //�����ա������ա������յ�������������
    static LONG tdayscount(LONG& outCount, LPCWSTR startTime, LPCWSTR endTime, LPCWSTR options = NULL);
    //////////////////////////////////////////////////////////////////////////

    //���׺���
    //////////////////////////////////////////////////////////////////////////
    //�����˺ŵ�½
    static LONG tlogon(WindData& outWindData, LPCWSTR brokerID, LPCWSTR departmentID, LPCWSTR accountID, LPCWSTR password, LPCWSTR accountType, LPCWSTR options = NULL);

    //�����˺ŵdz�, 0:�dz�ȫ���ѵ�¼���˺�
    static LONG tlogout(INT longId=0);

    //�µ�
    static LONG torder(WindData& outWindData, LPCWSTR windCodes, LPCWSTR tradeSide, LPCWSTR orderPrice, LPCWSTR orderVolume, LPCWSTR options = NULL);
    static LONG torder(LONG& reqId, LPCWSTR windCodes, LPCWSTR tradeSide, DOUBLE orderPrice, LONG orderVolume, LPCWSTR options = NULL, WCHAR** pErrosMsg = NULL);

    //����
    static LONG tcovered(WindData& outWindData, LPCWSTR windCodes, LPCWSTR tradeSide, LPCWSTR orderVolume, LPCWSTR options = NULL);
    static LONG tcovered(LONG& reqId, LPCWSTR windCodes, LPCWSTR tradeSide, LONG orderVolume, LPCWSTR options = NULL, WCHAR** pErrosMsg = NULL);

    //���������ѯ
    static LONG tquery(WindData& outWindData, LPCWSTR qryCode, LPCWSTR options = NULL);

    //����
    static LONG tcancel(LPCWSTR orderNumber, LPCWSTR options = NULL);
    //////////////////////////////////////////////////////////////////////////

    //�ز⺯��
    //////////////////////////////////////////////////////////////////////////
    //�ز⿪ʼ
    static LONG bktstart(WindData& outWindData, LPCWSTR strategyName, LPCWSTR startDate, LPCWSTR endDate, LPCWSTR options = NULL);

    //�ز��ѯ
    static LONG bktquery(WindData& outWindData, LPCWSTR qrycode, LPCWSTR qrytime, LPCWSTR options = NULL);

    //�ز��µ�
    static LONG bktorder(WindData& outWindData, LPCWSTR tradeTime, LPCWSTR securityCode, LPCWSTR tradeSide, LPCWSTR tradeVol, LPCWSTR options = NULL);

    //�ز����
    static LONG bktend(WindData& outWindData, LPCWSTR options);

    //�鿴�ز�״̬
    static LONG bktstatus(WindData& outWindData, LPCWSTR options);

    //�ز��Ҫ
    static LONG bktsummary(WindData& outWindData, LPCWSTR bktID, LPCWSTR view, LPCWSTR options);

    //�ز�ɾ��
    static LONG bktdelete(WindData& outWindData, LPCWSTR bktID, LPCWSTR options);

    //���ز����б�
    static LONG bktstrategy(WindData& outWindData, LPCWSTR options);

    //////////////////////////////////////////////////////////////////////////
};

#endif

.i file

/* File : WAPIWrapperCpp.i */
%module WAPIWrapperCpp

%{
#include "WAPIWrapperCpp.h"
%}

/* Let's just grab the original header file here */
%include <windows.i>
%include "WAPIWrapperCpp.h"

Error

Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.

WAPIWrapperCpp_wrap.cxx
E:\Workspace\Projects\bole\bole-app\src\main\resources\swig\WAPIWrapperCpp_wrap.cxx(434) : error C2182: 'result' : illegal use of type 'void'
E:\Workspace\Projects\bole\bole-app\src\main\resources\swig\WAPIWrapperCpp_wrap.cxx(440) : error C2440: '=' : cannot convert from 'void' to 'int'
Expressions of type void cannot be converted to other types
...

@vadz
Copy link
Member

vadz commented Mar 15, 2015

Surely you should be able to reduce this to something more minimal?

@wsfulton
Copy link
Member

Does your .h file really contain all those non-ascii looking characters as displayed here in Github?

@ojwb
Copy link
Member

ojwb commented Mar 17, 2015

I wonder if it is the use of VOID that is the issue. It doesn't look like SWIG's windows.i deals with that, so I'm guessing it gets handled by SWIG as an unknown type, and then windows.h presumably does #define VOID void and ... boom!

If that isn't it, a cut-down reproducer would be useful.

@wsfulton
Copy link
Member

wsfulton commented Jan 3, 2019

No response, closing

@wsfulton wsfulton closed this as completed Jan 3, 2019
@ojwb
Copy link
Member

ojwb commented Jan 4, 2019

@wsfulton Should windows.i handle VOID though? As I noted above that seems to be the underlying problem here.

I can't actually test with MSVC but simulating on Linux I get what looks like the equivalent GCC error with a small testcase:

$ cat test.i
%module test
%include <windows.i>
%inline %{
// #include <windows.h>
#ifndef SWIG
#define VOID void
#define INT int
#endif
VOID foo(INT) { }
%}
$ ../preinst-swig -c++ -python test.i 
$ g++ -fPIC `python3-config --cflags` -Wall -W -O2 test_wrap.cxx -shared
test_wrap.cxx: In function ‘PyObject* _wrap_foo(PyObject*, PyObject*)’:
test_wrap.cxx:2947:8: error: variable or field ‘result’ declared void
   VOID result;
        ^~~~~~
test_wrap.cxx:2956:3: error: ‘result’ was not declared in this scope
   result = foo(arg1);
   ^~~~~~
test_wrap.cxx:2956:3: note: suggested alternative: ‘resultobj’
   result = foo(arg1);
   ^~~~~~
   resultobj
test_wrap.cxx:2957:67: error: cannot declare reference to ‘const void’
   resultobj = SWIG_NewPointerObj((new VOID(static_cast< const VOID& >(result))), SWIGTYPE_p_VOID, SWIG_POINTER_OWN |  0 );
                                                                   ^
test_wrap.cxx:1102:89: note: in definition of macro ‘SWIG_NewPointerObj’
 #define SWIG_NewPointerObj(ptr, type, flags)            SWIG_Python_NewPointerObj(NULL, ptr, type, flags)
                                                                                         ^~~
test_wrap.cxx:2957:78: error: invalid use of ‘void’
   resultobj = SWIG_NewPointerObj((new VOID(static_cast< const VOID& >(result))), SWIGTYPE_p_VOID, SWIG_POINTER_OWN |  0 );
                                                                              ^
test_wrap.cxx:1102:89: note: in definition of macro ‘SWIG_NewPointerObj’
 #define SWIG_NewPointerObj(ptr, type, flags)            SWIG_Python_NewPointerObj(NULL, ptr, type, flags)
                                                                                         ^~~

If I add typedef void VOID; to Lib/windows.i and reprocess then the module compiles.

I've no idea what a purpose VOID is meant to serve though, so maybe that's not the right fix.

@wsfulton
Copy link
Member

wsfulton commented Jan 7, 2019

Thanks for the small reproducer @ojwb, that is what I think we were all hoping to get to the bottom of. I reproduced the error and and adding the appropriate definition from windows.h into windows.i.

@wsfulton wsfulton reopened this Jan 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants