-蚊香
代码移植参考文档
1
、
代码移植原则
编号
内容
1
2
工程:
所有的工程需要脱离
MFC,
直接建
立
win32
动态库;
库函数:
能够用标准
C/C++
函数实现的内容,
均用标准库函数实现;<
/p>
不能用标准库实现的函
数,需要封装,提供统一的函数;
代码:
?
代码中不再出现
stdafx.h
相关的内容;
?
代码中尽量不调用
win32/MFC
的函数,函数中不调用
“
MessageBox()
”
;
尽量不用
HANDLE<
/p>
、
HRESULT
、
HINSTANCE
、
HWND
、
LPCTSTR
、
WORD
、
DWORD
、
UINT
、
BYTE
、
byte
、
PBYTE
、
PTBYTE
、
BOOL
、
CFILE
等;
尽量用
char
、
long
、
int
、
unsi
gned
char
、
unsigned
long
、
unsigned
p>
int
、
bool
、
FILE*
等;
?
加载动
态库尽量不添加功能代码
(
winMain
、
InitInstance
中)
,
类似功能代码可
放在第一次调用相关函数时进行;
逻辑可有上层调用来控制;
也可以使用
linux
环境下的模块“构造函数“和“析构函数“
?
建立工程时,
工程名称,
文件名均采用小写;
#include
”
xx.h
”
时,也均
采用小写
的方式;
(注意
unix
p>
下文件名称大小写敏感)
?
API
函
数的输出需要定义统一规范,
使用
d
llexport
宏来输出,
还是在
.
def
文件
中定义;
?
Friend
函数的声明;定义为标准定义方法:
friend
class
CFridClass;
windows
下可以直接定义为<
/p>
friend
CFridClass;
?
GUID
操作函数,统一使用
basroot
70
中定义的
GUID
操作函数;
p>
?
取当前系统
本地时间函数,统一使用
basroot70
中定义的时间获取
函数;
?
3
2
、<
/p>
常见问题及解决方案
编号
问题
Windows
和
unix
版本的区分
解决方案
(1)
增加
basunixdef70
.h
头文件
,
改头文件中增加
MAPGIS7x_VERSION_UNIX
宏定义
;
(2) basdefine70.h
中增加如下代码
;
#ifdef
WIN32
#else
1
#include
“
basunixdef70.h
”
#endif
2
3
4
Windows
和
unix
下数据类型的
对照定义
文件操作
临界区操作
参考
basunixdef70.h
内容
所有的文件操作:打开,读写,判断文件是否存
在等,均采用
C
函数来实现;
1)
声
明
并
初
< br>始
化
:pthread_mutex_t
job_queue_mutex
=
PTHREAD_MUTEX_INITI
ALIZER; <
/p>
2)
上锁:
pthread_mutex
_lock (&job_queue_mutex);
3)
解
锁
:
pthread_mutex_
unlock
(&job_queue_mutex);
4
)
销
毁
:
pt
hread_mutex_destroy
(
job_queu
e_mutex
)
;
5
6
7
8
线程函数
虚拟内存操作
GUID
的产生
取当前系统模块路径
/
目录
pthread_create()
;
pthread_exit();
Linux
下没有
guid
的概念,<
/p>
需要编写
guid
操作函
数,由
basroot70
模块统一提供;
由
basroot70
模
块
统
一
提<
/p>
供
操
作
函
数
;
提
供
GetMoudleFileName()
的
模<
/p>
拟
函
数
;
提
供
_splitpath()
的模拟函数;
由
basr
oot70
模块统一提供操作函数;
#include
int
statfs(const
char
*path,
struct
statfs
*buf);
int
fstatfs(int
fd,
struct
statfs
*buf);
#include
<
sys/socket.h>
由
basroot70
提
供
统
一
的
loadlibra
ry(),
GetProcAddress(),FreeL
ibrary()
的模拟函数;
由<
/p>
basroot
提供模拟函数;
#pragma
pack(1);
//
以下
为
1
字节对齐
……
..
#pragma
pack();
//
以下为默认对齐
………
//
设置
1
字节对齐,在
linux
环境下如何修改
basdefine70.h
中结构的声明,需要讨论再确认。
(
Linux
下什么都不改,测试的结果和
windows
一样
??
)
在
C
程序中
:
可以用
access(
存在返
回
0,
不存在返回
-1
9
10
取当前系统时间
取磁盘信息函数
11
12
13
14
socket
相关函数
动态加载相关函数
strupr(),strcmpi()
1
字节对齐
15
判断文件是否存在
16
17
18
19
CString
ASSERT()/TRACE()
max()/min()
共
享库
加载
时
调
用的
函
,
类
似
InitInstance()
功能
,
会在
main()
< br>前
执行;
尽量改用
std::string
basroot70
提供该函数或宏的定义和实现;
void
__attribute__
my_init(void)
{
//user operator
}
((constructor))
20
共
享库
卸载
时调
用的
函数
,
似
ExitInstance()
功能,会在
main()
执行完以后,或
exit()
以后被调
用
;
void
__attribute__
((destructor))
my_fini(void)
{
//user operator
}
//
动态库加载和卸载时的函数可以调用可以用全
局变量来模
拟;
这里需要讨论,
是用
my_init
(
)
类似
的函数,还是用全局变量
,
或者别的新方案
;
sleep()
:单位为秒;
usleep()
:单位为微秒
Linux
下目录分隔符只能为
p>
’
/
’
,不能为<
/p>
’
’
;
1
、
gcc/g++
环境下所有的
api
函数,缺省都是导
出的;如果不作控制将使导出的符号太多,
< br>降低运行速度;
2
、
如
p>
果
不
导
出
,
只
共
内
部
使
用
,
< br>可
添
加
__attribute
__
((visibility(
或
__attribute__ ((visibility(
属性来控
< br>制;
3
、
MAP
GIS
移植中如果要控制内部函数不导出
符号;可加
GIS_FUCIN
来控制;如
Long
GIS_FUCIN
CreateTbl(std::string
sql);
1
、
按常规函数实现;但不声明于头文件中;
2
、
使用时添加声明后便可使用了;如下示例:
extern
“
C
”
{
long myfunction(char*p);
}
Long Fun1(char *p)
{
myfunction(p);
}
在
basroot70
中增加模拟函数;
1
、
windows/linux
下读写同一个文件,内容是一
p>
21
Sleep()
:
(
注意:其单位为毫秒
)
目录分隔符
函数隐藏
22
23
24
函数匿名导出
25
26
GetCurrentDirectory()/Set
Current
Directory()
跨平台文件的读写;
致的;
2
、
判断一个文件是否存在,不存在则创建的代
码;
FILE * fp=NULL;
fp=fopen(
if(fp==NULL)
{
fp=fopen(
}
3
、
常用
函数及对应
/
替代函数
编号
1
Windows
函数
Loadlibray()
Linux
下对应函数
#include
void *
dlopen(const char *pathname, int mode);
int dlclose (void *handle);
void *dlsym(void *handle, char
*symbol);
strcpy()
strncpy()
无
strcasecmp()
无
chdir()
sprintf();
sprintf();
Linux:
sprintf(szbuf,
“
l
ld%
”
, i64val);
windows:
sprintf(szbuf,
“
I64d%
”
,
i64val);
gettimeofday()
m_ptTxt[0] = '0';
bcopy(),memcpy()
;
PATH_MAX
(=4096)
getcwd(char *buf, size_t
size);
chdir(const char *
path);
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Freelibrary()
GetProcAddress()
lstrcpy()
lstrcpyn
strupr
strcmpi()
_chdrive()
_chdir()
ltoa()/_ltoa()
itoa()/_itoa()
i64toa()
GetLocalTime()
m_ptTxt[0]=0
CopyMemory
GetCurrentDirectory()
_MAX_PA
TH
GetCurrentDirectory()
SetCurrentDirectory()
GetModuleFileName()
readlink(“/proc/self/exe”,char*buf,
size_t bufsiz);
SetCurrentDirectory ()
-蚊香
-蚊香
-蚊香
-蚊香
-蚊香
-蚊香
-蚊香
-蚊香
-
上一篇:环境科学与工程专业英语重点翻译
下一篇:2017年6月英语四级真题 (第3套)