You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.4 KiB
61 lines
1.4 KiB
#include "util.h"
|
|
|
|
|
|
string ConvertToString(System::String^ str)
|
|
{
|
|
char* p = (char*)(void*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(str);
|
|
return p;
|
|
}
|
|
System::String ^ convert_to_cstring(const char *p)
|
|
{
|
|
return System::Runtime::InteropServices::Marshal::PtrToStringAnsi((System::IntPtr)(char *)p);
|
|
}
|
|
bool isTypeOf(tag_t objtag, const char * type_name) {
|
|
tag_t type = NULLTAG;
|
|
TCTYPE_ask_object_type(objtag, &type);
|
|
tag_t item_type = NULLTAG;
|
|
TCTYPE_find_type(type_name, "", &item_type);
|
|
bool is_type = false;
|
|
if (item_type != NULLTAG) {
|
|
logical isok = FALSE;
|
|
TCTYPE_is_type_of(type, item_type, &isok);
|
|
if (isok) {
|
|
is_type = true;
|
|
}
|
|
}
|
|
return is_type;
|
|
}
|
|
void split(std::string s, const char* delim, std::vector<std::string>* ret)
|
|
{
|
|
size_t last = 0;
|
|
size_t index = s.find(delim, last);
|
|
int size = strlen(delim);
|
|
while (index != std::string::npos) {
|
|
ret->push_back(s.substr(last, index - last));
|
|
last = index + size;
|
|
index = s.find(delim, last);
|
|
}
|
|
if (index - last > 0) {
|
|
ret->push_back(s.substr(last, index - last));
|
|
}
|
|
}
|
|
|
|
const char* newGUID()
|
|
{
|
|
static char buf[64] = { 0 };
|
|
GUID guid;
|
|
if (S_OK == ::CoCreateGuid(&guid))
|
|
{
|
|
_snprintf(buf, sizeof(buf)
|
|
, "%08X-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02X"
|
|
, guid.Data1
|
|
, guid.Data2
|
|
, guid.Data3
|
|
, guid.Data4[0], guid.Data4[1]
|
|
, guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5]
|
|
, guid.Data4[6], guid.Data4[7]
|
|
);
|
|
}
|
|
return (const char*)buf;
|
|
|
|
} |