Tuesday, September 13, 2022

Swift call C++ code and class

 [Reference]

https://stackoverflow.com/questions/35229149/interacting-with-c-classes-from-swift

https://stackoverflow.com/questions/2045774/developing-c-wrapper-api-for-object-oriented-c-code/2045860

Swift can not call C++ code directly. C++ code must be wrapped by C, Objective-C or Objective-C++. Swift uses the wrapper (wrapped code) to call C++ code. According to the references, an example is shown as the following:

C++ header (MPoint3.hpp)

#pragma once
class MPoint3
{
public:
    double x;
    double y;
    double z;
};

C wrapper header (MPoint3C.h)

#ifndef MPoint3C_h
#define MPoint3C_h

#ifdef __cplusplus
extern "C" {
#endif

typedef struct
{
    double x;
    double y;
    double z;
} MPoint3C;

MPoint3C* MPoint3_Constructor(void);
void MPoint3_Destructor(MPoint3C*);

#ifdef __cplusplus
}
#endif

#endif


C++ source (MPoint3C.cpp)

#include "MPoint3.hpp"
#include "MPoint3C.h"

#ifdef __cplusplus
extern "C" {
#endif

MPoint3C* MPoint3_Constructor(void)
{
	return (MPoint3C*) new MPoint3;
}

void MPoint3_Destructor(MPoint3C* ppt)
{
	delete (MPoint3*)ppt;
}

#ifdef __cplusplus
}
#endif


Use in Swift (swift.swift)

let pPt = MPoint3_Constructor()   // The type of pPt is UnsafeMutablePointer<MPoint3C>

pPt.pointee.x = 10
pPt.pointee.y = 11
pPt.pointee.z = 12

MPoint3_Destructor(pPt)


Thursday, September 8, 2022

關於 iOS Swift 程式開發的一些事

 

[取用 C++ 的程式碼]

https://stackoverflow.com/questions/32541268/can-i-have-swift-objective-c-c-and-c-files-in-the-same-xcode-project/32546879#32546879

https://stackoverflow.com/questions/35229149/interacting-with-c-classes-from-swift

https://stackoverflow.com/questions/2045774/developing-c-wrapper-api-for-object-oriented-c-code/2045860

Swift 不能直接取用 C++的程式碼,必須先包裝成 C 或 Object-C++ 程式碼再取用。並且需要 Bridgeing-Header。





Wednesday, August 31, 2022

[GitLab][SSH] TortoiseGit 使用 SSH

 1. 在 Windows 安裝 SSH.

https://docs.microsoft.com/zh-tw/windows-server/administration/openssh/openssh_install_firstuse

2. 產生 SSH private & public key, 及用於 TortoiseGit.

https://backlog.com/git-tutorial/tw/reference/ssh.html


Saturday, July 9, 2022

[OpenGL] 光影 - Shadow

 [Reference] https://learnopengl.com/Advanced-Lighting/Shadows/Shadow-Mapping

[需使用 VAO 和 shader,可參考 https://blog.csdn.net/p942005405/article/details/103767695。]

1. 從光源看場景,產生 Depth Map,用來決定某個位置的光線是否被遮蔽,正式場照中應該有陰影。

2. 在 Shader 中把陰影位置的顏色變暗,成陰影。

3. 使用 VAO 時,模型矩陣變換在 shader 中完成? 

Sunday, June 5, 2022

xercesc xml encoding 問題

xercesc 內部使用 Unicode (UTF-16) 編碼, 輸出檔案時,使用多字元 (UTF-8) 編碼? 

使用 UltraEditor 開啟 xml, kml 檔案時,使用 Hex 模式 查看時, 會發現 UltraEditor (Ver. 10.20+, V 10 不會出錯) 會在檔頭加上Unicode 識別嗎 FFFE,並 以 Unicode 顯示,但其實檔案內容還是 multibyte,不要被騙了。 Unicode,  

xercesc 自訂變數型態

        XMLCh = char16_t

其實就是雙字元 (Unicode), wchar_t, 但不能直接轉換。

        XMLCh* xmlCh;

        wchar_t* ws = xmlCh;   //不能這麼做

但,可以用強制轉換:

        wchar_t* ws = (wchar_t*)xmlCh

在 xercesc 的函數使用到 XMLCh* 參數時,

英文及數字可以用 XMLString::transcode() 轉換為 XMLCh,例如:

        XMLCh* xmlCh =  XMLString::transcode("abc");

        DOMElement* nodeFolder = pDOM->createElement(XMLString::transcode("Folder"));

UTF-8編碼的文字必須先轉換成 wchar_t (就是Unicode啦), 再直接轉換成 XMLCh*,不必用XMLString::transcode()。 

Sunday, April 3, 2022

LNK2001 無法解析的外部符號 "public: virtual struct QMetaObject const * __cdecl xxxxxxxxx

 狀況:

    明明已經把 .cpp, .ui 檔加入專案,但編譯仍然報錯 LNK2001 無法解析的外部符號。

解方:

    把 .h 檔裏的 Q_OBJECT 刪去,重新編譯即可。

    為什麼,我也不知道。

Saturday, March 19, 2022

MSB4181 "QtRunWork" 工作傳回了 False,但未記錄錯誤

找了很多網頁,都說要把 Qt 延伸模組降版本,但一直試不成功。而另一支程式卻沒有這個問題。

其實我遇到的問題和其他人不同,再仔細看一次編譯訊息,原來是專案找到到某些檔案,因為在另一台電腦工作時沒有加入 Git,所以沒有 Pull 到本機。找回少的檔案就解決了。





[Qt] 執行檔需要哪些 Dll?

 1. 使用 Qt  的 windeployqt.exe 工具 (在 C:\Qt\Qt5.14.1\5.14.1\msvc2017\bin\)。   a. 把執行檔 myProgram.exe 放在某個資料夾。   b. 在檔案總管這個資料夾按 Shift 和滑鼠右鍵,開啟 Po...