cpapi

package module
v0.0.1-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 5, 2020 License: MIT Imports: 11 Imported by: 0

README

cpapi

Creon Plus (Cybos Plus) Wrapper for Go - 작성 중입니다.

이 패키지는 크레온 플러스(사이보스 플러스)를 golang 에서 사용할 수 있도록 만든 것입니다. gocp 패키지 https://github.com/ippoeyeslhw/cpgo go-ole 패키지 https://github.com/go-ole/go-ole 위 두 패키지를 가져와 일부를 수정한 것입니다.

설명

  • golang을 64bit로 설치한 경우에는 컴파일 시 32bit 크로스 컴파일 하여야 합니다. cmd(명령프롬프트) 에서는 set GOARCH=386 VSCODE와 같이 PS(파워쉘) 터미널일 경우에는 $ENV:GOARCH=386 으로 하면 32bit로 컴파일 할 수 있습니다.

  • cpgo에서 수정한 내용 cpgo에 없는 크레온 플러스의 함수 일부 추가하였습니다. CpClass 구조체 내부의 변수 중 obj가 로컬변수여서 정의 되어있지 않는 크레온의 함수를 사용할 수 없어 전역변수(Obj)로 변경하여 참조할 수 있도록 하였습니다.

원 cpgo 패키지에서는 blockrequest와 request 둘다 가능했지만 이 패키지에서는 blockrequest만 가능합니다. (쓰레드를 만들기 위해 C를 임포트할 경우 크로스 컴파일이 안되는 문제가 있어 뺀것으로 추후 넣을 예정입니다.)

  • go-ole에서 수정한 내용 go-ole의 idispatch_windows.go 파일의 invoke 함수에는 string 과 int32의 슬라이스를 지원하지 않아 func invoke 내의 switch문에 - case []string:, case []int32: 을 추가 했습니다. - 일괄 조회 가능하도록 함 그리고 크레온 플러스를 사용하는데 필요없는 파일 및 함수는 정리해서 간략화 했습니다.

사용방법

  • import

import ( "github.com/hspan/cpapi" )

  • 프로그램 시작 cpapi.CoInitialize(0) defer cpapi.CoUninitialize()

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// IID_IUnknown is for IUnknown interfaces.
	IID_IUnknown = NewGUID("{00000000-0000-0000-C000-000000000046}")

	// IID_IDispatch is for IDispatch interfaces.
	IID_IDispatch = NewGUID("{00020400-0000-0000-C000-000000000046}")

	// IID_NULL is null Interface ID, used when no other Interface ID is known.
	IID_NULL = NewGUID("{00000000-0000-0000-0000-000000000000}")
)

Functions

func BstrToString

func BstrToString(p *uint16) string

BstrToString converts COM binary string to Go string.

func CoInitialize

func CoInitialize(p uintptr) (err error)

CoInitialize initializes COM library on current thread.

MSDN documentation suggests that this function should not be called. Call CoInitializeEx() instead. The reason has to do with threading and this function is only for single-threaded apartments.

That said, most users of the library have gotten away with just this function. If you are experiencing threading issues, then use CoInitializeEx().

func CoInitializeEx

func CoInitializeEx(p uintptr, coinit uint32) (err error)

CoInitializeEx initializes COM library with concurrency model.

func CoUninitialize

func CoUninitialize()

CoUninitialize uninitializes COM Library.

func GetUserDefaultLCID

func GetUserDefaultLCID() (lcid uint32)

GetUserDefaultLCID retrieves current user default locale.

func GetVariantDate

func GetVariantDate(value uint64) (time.Time, error)

GetVariantDate converts COM Variant Time value to Go time.Time.

func IsUserAnAdmin

func IsUserAnAdmin() (bool, error)

func LpOleStrToString

func LpOleStrToString(p *uint16) string

LpOleStrToString converts COM Unicode to Go string.

func RetInt

func RetInt(r *VARIANT) (ret int)

func RetSS

func RetSS(r *VARIANT) (ret []string)

func RetStr

func RetStr(r *VARIANT) (ret string)

func RunCP

func RunCP(cmdName string, arg ...string) bool

RunCP - 크레온 플러스 실행 cmdName : creon plus의 starter.exe 의 경로 arg :

func SysAllocStringLen

func SysAllocStringLen(v string) (ss *int16)

SysAllocStringLen copies up to length of given string returning pointer.

func SysFreeString

func SysFreeString(v *int16) (err error)

SysFreeString frees string system memory. This must be called with SysAllocString.

func SysStringLen

func SysStringLen(v *int16) uint32

SysStringLen is the length of the system allocated string.

func VariantClear

func VariantClear(v *VARIANT) (err error)

VariantClear clears value in Variant settings to VT_EMPTY.

func VariantInit

func VariantInit(v *VARIANT) (err error)

VariantInit initializes variant.

Types

type CpClass

type CpClass struct {
	Obj *IDispatch
	// contains filtered or unexported fields
}

사이보스플러스 또는 크레온플러스 객체

func (*CpClass) BlockRequest

func (c *CpClass) BlockRequest()

사이보스플러스 BlockRequest 메서드 Wrapper

func (*CpClass) CodeToName

func (c *CpClass) CodeToName(cod string) (r *VARIANT)

CodeToName : 입력된 종목코드에 대응하는 종목명을 반환함 CpUtil.CpStockCode.CodeToName, CpUtil.CpCodeMgr.CodeToName 입력 : cod - string (종목코드) 출력 : name - string (종목명)

func (*CpClass) Create

func (c *CpClass) Create(name string)

func (*CpClass) GetDataValue

func (c *CpClass) GetDataValue(typ int, idx int) (result *VARIANT)

사이보스플러스 GetDataValue 메서드 Wrapper

func (*CpClass) GetHeaderValue

func (c *CpClass) GetHeaderValue(typ int) (result *VARIANT)

사이보스플러스 GetHeaderValue 메서드 Wrapper

func (*CpClass) GetStockListByMarket

func (c *CpClass) GetStockListByMarket(cod int) (r *VARIANT)
GetStockListByMarket : 코스피와 코스닥 종목 코드 전달

CpUtil.CpCodeMgr.GetStockListByMarket 입력 : mcode - 시장 코드 (코스피 1, 코스 2) 리턴 : codes - 문자열 slice (종목코드들)

func (*CpClass) GetStockListedDate

func (c *CpClass) GetStockListedDate(cod string) (r *VARIANT)

GetStockListedDate : 입력된 종목코드에 해당하는 상장사의 상장일을 리턴함 CpUtil.CpCodeMgr.GetStockListedDate 입력 : cod - string (종목코드) 리턴 : ret - int (상장일을 yyyymmdd 형태의 정수로 반환함 - 문자열이나 date로 변환 필요함)

func (*CpClass) GetStockSectionKind

func (c *CpClass) GetStockSectionKind(cod string) (r *VARIANT)

func (*CpClass) GetStockStatusKind

func (c *CpClass) GetStockStatusKind(cod string) (r *VARIANT)

GetStockStatusKind : 입력된 종목코드에 해당하는 상태를 리턴함 CpUtil.CpCodeMgr.GetStockStatusKind 입력 : cod - string (종목코드) 리턴 : ret - int (주식상태 0: 정상, 1: 거래정지 2: 거래중단)

func (*CpClass) GetStockSupervisionKind

func (c *CpClass) GetStockSupervisionKind(cod string) (r *VARIANT)

GetStockSupervisionKind : 입력된 종목코드에 해당하는 상태를 리턴함 CpUtil.CpCodeMgr.GetStockSupervisionKind 입력 : cod - string (종목코드) 리턴 : ret - int (관리구분 0: 일반종목, 1: 관리종목)

func (*CpClass) IsConnect

func (c *CpClass) IsConnect() (r *VARIANT)

사이보스플러스 CpUtil.CpCybos ServerType Property getter

func (*CpClass) IsSPAC

func (c *CpClass) IsSPAC(cod string) (r *VARIANT)

IsSPAC 스펙 여부를 반환한다.

func (*CpClass) NameToCode

func (c *CpClass) NameToCode(nm string) (r *VARIANT)

사이보스플러스 CpUtil.CpStockCode NameToCode 메서드 Wrapper

func (*CpClass) Release

func (c *CpClass) Release()

Create 메서드로 생성한 객체 헤제할 때 사용합니다.

func (*CpClass) SetInputValue

func (c *CpClass) SetInputValue(typ int, val interface{})

사이보스플러스 SetInputValue 메서드 Wrapper

type DISPPARAMS

type DISPPARAMS struct {
	// contains filtered or unexported fields
}

DISPPARAMS are the arguments that passed to methods or property.

type EXCEPINFO

type EXCEPINFO struct {
	// contains filtered or unexported fields
}

EXCEPINFO defines exception info.

func (EXCEPINFO) Error

func (e EXCEPINFO) Error() string

Error implements error interface and returns error string.

type GUID

type GUID struct {
	Data1 uint32
	Data2 uint16
	Data3 uint16
	Data4 [8]byte
}

GUID is Windows API specific GUID type.

This exists to match Windows GUID type for direct passing for COM. Format is in xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxxx.

func CLSIDFromString

func CLSIDFromString(str string) (clsid *GUID, err error)

CLSIDFromString retrieves Class ID from string representation.

This is technically the string version of the GUID and will convert the string to object.

CLSIDFromString in Windows API.

func NewGUID

func NewGUID(guid string) *GUID

NewGUID converts the given string into a globally unique identifier that is compliant with the Windows API.

The supplied string may be in any of these formats:

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}

The conversion of the supplied string is not case-sensitive.

type IDispatch

type IDispatch struct {
	IUnknown
}

func (*IDispatch) GetIDsOfName

func (v *IDispatch) GetIDsOfName(names []string) (dispid []int32, err error)

func (*IDispatch) GetSingleIDOfName

func (v *IDispatch) GetSingleIDOfName(name string) (displayID int32, err error)

GetSingleIDOfName is a helper that returns single display ID for IDispatch name.

This replaces the common pattern of attempting to get a single name from the list of available IDs. It gives the first ID, if it is available.

func (*IDispatch) Invoke

func (v *IDispatch) Invoke(dispid int32, dispatch int16, params ...interface{}) (result *VARIANT, err error)

func (*IDispatch) InvokeWithOptionalArgs

func (v *IDispatch) InvokeWithOptionalArgs(name string, dispatch int16, params []interface{}) (result *VARIANT, err error)

InvokeWithOptionalArgs accepts arguments as an array, works like Invoke.

Accepts name and will attempt to retrieve Display ID to pass to Invoke.

Passing params as an array is a workaround that could be fixed in later versions of Go that prevent passing empty params. During testing it was discovered that this is an acceptable way of getting around not being able to pass params normally.

func (*IDispatch) VTable

func (v *IDispatch) VTable() *IDispatchVtbl

type IDispatchVtbl

type IDispatchVtbl struct {
	IUnknownVtbl
	GetTypeInfoCount uintptr
	GetTypeInfo      uintptr
	GetIDsOfNames    uintptr
	Invoke           uintptr
}

type IUnknown

type IUnknown struct {
	RawVTable *interface{}
}

func CreateInstance

func CreateInstance(clsid *GUID, iid *GUID) (unk *IUnknown, err error)

CreateInstance of single uninitialized object with GUID.

func (*IUnknown) QueryInterface

func (v *IUnknown) QueryInterface(iid *GUID) (*IDispatch, error)

func (*IUnknown) Release

func (v *IUnknown) Release() int32

func (*IUnknown) VTable

func (v *IUnknown) VTable() *IUnknownVtbl

type IUnknownVtbl

type IUnknownVtbl struct {
	QueryInterface uintptr
	AddRef         uintptr
	Release        uintptr
}

type OleError

type OleError struct {
	// contains filtered or unexported fields
}

OleError stores COM errors.

func NewError

func NewError(hr uintptr) *OleError

NewError creates new error with HResult.

func NewErrorWithSubError

func NewErrorWithSubError(hr uintptr, description string, err error) *OleError

NewErrorWithSubError creates new COM error with parent error.

func (*OleError) Code

func (v *OleError) Code() uintptr

Code is the HResult.

func (*OleError) Description

func (v *OleError) Description() string

Description retrieves error summary, if there is one.

func (*OleError) Error

func (v *OleError) Error() string

Error implements error interface.

func (*OleError) String

func (v *OleError) String() string

String description, either manually set or format message with error code.

func (*OleError) SubError

func (v *OleError) SubError() error

SubError returns parent error, if there is one.

type SafeArray

type SafeArray struct {
	Dimensions   uint16
	FeaturesFlag uint16
	ElementsSize uint32
	LocksAmount  uint32
	Data         uint32
	Bounds       [16]byte
}

SafeArray is how COM handles arrays.

type SafeArrayConversion

type SafeArrayConversion struct {
	Array *SafeArray
}

func (*SafeArrayConversion) GetDimensions

func (sac *SafeArrayConversion) GetDimensions() (dimensions *uint32, err error)

func (*SafeArrayConversion) GetSize

func (sac *SafeArrayConversion) GetSize() (length *uint32, err error)

func (*SafeArrayConversion) GetType

func (sac *SafeArrayConversion) GetType() (varType uint16, err error)

func (*SafeArrayConversion) Release

func (sac *SafeArrayConversion) Release()

Release Safe Array memory

func (*SafeArrayConversion) ToByteArray

func (sac *SafeArrayConversion) ToByteArray() (bytes []byte)

func (*SafeArrayConversion) ToStringArray

func (sac *SafeArrayConversion) ToStringArray() (strings []string)

func (*SafeArrayConversion) ToValueArray

func (sac *SafeArrayConversion) ToValueArray() (values []interface{})

func (*SafeArrayConversion) TotalElements

func (sac *SafeArrayConversion) TotalElements(index uint32) (totalElements int32, err error)

type VARIANT

type VARIANT struct {
	VT VT //  2

	Val int64 // 16
	// contains filtered or unexported fields
}

func CallMethod

func CallMethod(disp *IDispatch, name string, params ...interface{}) (result *VARIANT, err error)

CallMethod calls method on IDispatch with parameters.

func GetProperty

func GetProperty(disp *IDispatch, name string, params ...interface{}) (result *VARIANT, err error)

GetProperty retrieves property from IDispatch.

func MustCallMethod

func MustCallMethod(disp *IDispatch, name string, params ...interface{}) (result *VARIANT)

MustCallMethod calls method on IDispatch with parameters or panics.

func MustGetProperty

func MustGetProperty(disp *IDispatch, name string, params ...interface{}) (result *VARIANT)

MustGetProperty retrieves property from IDispatch or panics.

func NewVariant

func NewVariant(vt VT, val int64) VARIANT

NewVariant returns new variant based on type and value.

func (*VARIANT) ToArray

func (v *VARIANT) ToArray() *SafeArrayConversion

ToArray converts variant to SafeArray helper.

func (*VARIANT) ToIDispatch

func (v *VARIANT) ToIDispatch() *IDispatch

ToIDispatch converts variant to dispatch object.

func (*VARIANT) ToIUnknown

func (v *VARIANT) ToIUnknown() *IUnknown

ToIUnknown converts Variant to Unknown object.

func (*VARIANT) ToString

func (v *VARIANT) ToString() string

ToString converts variant to Go string.

func (*VARIANT) Value

func (v *VARIANT) Value() interface{}

Value returns variant value based on its type.

Currently supported types: 2- and 4-byte integers, strings, bools. Note that 64-bit integers, datetimes, and other types are stored as strings and will be returned as strings.

Needs to be further converted, because this returns an interface{}.

type VT

type VT uint16
const (
	CLSCTX_INPROC_SERVER   = 1
	CLSCTX_INPROC_HANDLER  = 2
	CLSCTX_LOCAL_SERVER    = 4
	CLSCTX_INPROC_SERVER16 = 8
	CLSCTX_REMOTE_SERVER   = 16
	CLSCTX_ALL             = CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER | CLSCTX_LOCAL_SERVER
	CLSCTX_INPROC          = CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER
	CLSCTX_SERVER          = CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER

	DISPATCH_PROPERTYPUT       = 4
	DISPATCH_PROPERTYPUTREF    = 8
	DISPID_PROPERTYPUT         = -3
	DISPATCH_METHOD            = 1
	DISPATCH_PROPERTYGET       = 2
	VT_EMPTY                VT = 0x0
	VT_NULL                 VT = 0x1
	VT_I2                   VT = 0x2
	VT_I4                   VT = 0x3
	VT_R4                   VT = 0x4
	VT_R8                   VT = 0x5
	VT_CY                   VT = 0x6
	VT_DATE                 VT = 0x7
	VT_BSTR                 VT = 0x8
	VT_DISPATCH             VT = 0x9
	VT_ERROR                VT = 0xa
	VT_BOOL                 VT = 0xb
	VT_VARIANT              VT = 0xc
	VT_UNKNOWN              VT = 0xd
	VT_DECIMAL              VT = 0xe
	VT_I1                   VT = 0x10
	VT_UI1                  VT = 0x11
	VT_UI2                  VT = 0x12
	VT_UI4                  VT = 0x13
	VT_I8                   VT = 0x14
	VT_UI8                  VT = 0x15
	VT_INT                  VT = 0x16
	VT_UINT                 VT = 0x17
	VT_VOID                 VT = 0x18
	VT_HRESULT              VT = 0x19
	VT_PTR                  VT = 0x1a
	VT_SAFEARRAY            VT = 0x1b
	VT_CARRAY               VT = 0x1c
	VT_USERDEFINED          VT = 0x1d
	VT_LPSTR                VT = 0x1e
	VT_LPWSTR               VT = 0x1f
	VT_RECORD               VT = 0x24
	VT_INT_PTR              VT = 0x25
	VT_UINT_PTR             VT = 0x26
	VT_FILETIME             VT = 0x40
	VT_BLOB                 VT = 0x41
	VT_STREAM               VT = 0x42
	VT_STORAGE              VT = 0x43
	VT_STREAMED_OBJECT      VT = 0x44
	VT_STORED_OBJECT        VT = 0x45
	VT_BLOB_OBJECT          VT = 0x46
	VT_CF                   VT = 0x47
	VT_CLSID                VT = 0x48
	VT_BSTR_BLOB            VT = 0xfff
	VT_VECTOR               VT = 0x1000
	VT_ARRAY                VT = 0x2000
	VT_BYREF                VT = 0x4000
	VT_RESERVED             VT = 0x8000
	VT_ILLEGAL              VT = 0xffff
	VT_ILLEGALMASKED        VT = 0xfff
	VT_TYPEMASK             VT = 0xfff
)

Directories

Path Synopsis
go-ole module
oleutil Module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL