Tuesday, June 3, 2008

成功运行iphone sdk

由于没有mac id,偶只通过讯雷下载了一个最老版本的iphone sdk, 2.1GB之巨啊!安装好之后需要4.5GB!

安装好之后问题又来了,我的PS/2键盘右不能用了!上网查,最后把鼠标也换成PS/2口的,搞定!
看看hello world吧


现在这篇blog也是在Mac下面发表的,哈哈

Monday, June 2, 2008

安装Mac OS X Leopard成功

为了体验Mac的魅力和感受iphone开发环境,我尝试安装 Mac OS X Leopard 到我的PC上,安装很顺利,下面是截图

真的是很漂亮啊,马上装好msn和QQ,以及office 2008, iWork,试用心仪已久的Keynotes,真是太爽了,唯一有缺憾的是不支持PS/2键盘,后来找到这个,安装好之后PS/2键盘也可以用啦,完美了。

最后列一下我的配置
CPU: E8400
内存: 宇瞻 ddr2 667 1G + 亿能 ddr2 800 2G
硬盘: Matrox 40G 硬盘 IDE
显卡: Geforce 7600GS
主板: 技嘉EP35-DS3
PS/2键盘
USB 鼠标

安装的版本为Mac OS X Leopard 10.5.2-Kalyway

Friday, August 24, 2007

VS2005在dll中使用CString时的link错误解决方案


You may receive an LNK2019 error message when you build a Visual C++ 2005 or Visual C++ .NET application that uses a CString-derived class from a DLL file























Article ID:309801
Last Review:January 9, 2006
Revision:3.0


This article was previously published under Q309801

Note Microsoft Visual C++ 2005, Microsoft Visual C++ .NET 2003, and Microsoft Visual C++ .NET 2002 support both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model. The information in this article applies only to unmanaged Visual C++ code.




SYMPTOMS



When you build a Visual C++ 2005 or Visual C++ .NET application that uses a CString-derived class from a DLL file, you may receive an error message that is similar to one of the following:

Message 1
ClientProject error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall ATL::CStringT<char,class StrTraitMFC<char,class ATL::ChTraitsCRT<char>>>::CStringT<char,class StrTraitMFC<char,class ATL::ChTraitsCRT<char>>>(char const *)" (__imp_??0?$CStringT@DV?$StrTraitMFC@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@QAE@PBD@Z) referenced in function _main

Message 2
ClientProject error LNK2005: "public: __thiscall ATL::CStringT<char,class StrTraitMFC<char,class ATL::ChTraitsCRT<char>>>::~CStringT<char,class StrTraitMFC<char,class ATL::ChTraitsCRT<char>>>(void)" (??1?$CStringT@DV?$StrTraitMFC@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@QAE@XZ) already defined in Simple.obj

Message 3
ClientProject fatal error LNK1169: one or more multiply defined symbols found

Back to the top



CAUSE



This behavior may occur if you use a class derived from CString that is also exported from a DLL.

In Microsoft Visual Studio 2005 or in Microsoft Visual Studio .NET, the CString class has changed to a template class, as demonstrated by the following lines of code taken from afxstr.h:

typedef ATL::CStringT< wchar_t, StrTraitMFC< wchar_t > > CStringW;
typedef ATL::CStringT< char, StrTraitMFC< char > > CStringA;
typedef ATL::CStringT< TCHAR, StrTraitMFC< TCHAR > > CString;


Visual Studio automatically exports the appropriate template instantiation for the CStringT template class that you derive from. However, when you import the class, Visual Studio .NET sometimes does not correctly import that instantiation. This results in the linker error messages listed in the "Symptoms" section of this article.

Back to the top



RESOLUTION



To resolve this issue, explicitly import the template class for CStringT and CSimpleStringT in the precompiled header (stdafx.h) file, as follows:

template class __declspec(dllimport) CStringT<TCHAR, StrTraitMFC<TCHAR, ChTraitsCRT<TCHAR> > >;
template class __declspec(dllimport) CSimpleStringT<TCHAR>;


Back to the top



MORE INFORMATION




Steps to Reproduce the Problem






































































1.In Visual C++ 2005 or in Visual C++ .NET, create a default MFC DLL project.
2.On the Project menu, click Add New Item.
3.Name the file MyString.h. Select the Header File template, and then click Open.

Note In Visual Studio 2005, click Add instead of Open.
4.Add the following code to MyString.h:

#ifdef _USRDLL
#define IMPEXP __declspec(dllexport)
#else
#define IMPEXP __declspec(dllimport)
#endif

class IMPEXP CMyString: public CString
{
public:
CMyString();
virtual ~CMyString();

void MyMethod();
};

5.Add a new C++ source file to the project named MyString.cpp.
6.Add the following code to MyString.cpp:

#include "StdAfx.h"
#include "mystring.h"

CMyString::CMyString(void) {}
CMyString::~CMyString(void) {}

void CMyString::MyMethod(void)
{
AfxMessageBox("foo is called");
//In Visual C++ 2005, you should rewrite this setence to "AfxMessageBox(L"foo is called");"
}

7.Save and build the DLL project.
8.Create a new Win32 Project. In the wizard, change the setting under Application Settings to the Console Application type, and then click to select the MFC checkbox to add MFC support.
9.In the new application's main source file, include MyString.h from the DLL project. Verify that the correct full path or relative path is being used.
10.Before the main function, add a #pragma to link to the library for the DLL (again, be sure to use a correct full path or relative path), as follows:

#pragma comment(lib, "..\\Debug\\TestDll.lib")

11.Add the following code in the else block of the main function:

// TODO: code your application's behavior here.
CString strHello = "Hello";
CMyString* myStr = new CMyString();
myStr->MyMethod();


Note In Visual C++ 2005, you must add the common language runtime support compiler option (/clr:oldSyntax) to successfully compile the previous code sample. To add the common language runtime support compiler option, follow these steps:



















1.Click Project, and then click ProjectName Properties.

Note ProjectName is a placeholder for the name of the project.
2.Expand Configuration Properties, and then click General.
3.In the right pane, click to select Common Language Runtime Support, Old Syntax (/clr:oldSyntax) in the Common Language Runtime support project settings.
4.Click Apply, and then click OK.

For more information about common language runtime support compiler options, visit the following Microsoft Developer Network (MSDN) Web site:
http://msdn2.microsoft.com/en-us/library/k8d11d4s.aspx (http://msdn2.microsoft.com/en-us/library/k8d11d4s.aspx)

12.Build the project.

The build fails with the "LNK2019" error.
13.In the console application, add a new C++ source file named Simple.cpp.
14.Add the following code to Simple.cpp:

#include "stdafx.h"
CString bar()
{
CString s = "Hi";
return s;
}

15.Build the project again.

You receive the "LNK2005" and "LNK1169" error messages.
16.Apply the solution provided in the "Resolution" section of this article.

The project should now build without errors.



Thursday, August 23, 2007

Nokia将逐渐放弃CodeWarrior


Forum Nokia 宣布将在2008年逐渐放弃CodeWarrior作为Symbian平台开发工具,最终转移到Carbide C++。到此,Nokia终于结束开发工具依赖第三方公司产品的局面(Carbide虽然是基于Eclips,但是这个是开源的)


Tuesday, August 14, 2007

深入理解CBase类--6个基础问题


摘抄自


http://www.newlc.com/inside-cbase-class-six-essential-questions




如果你可以回答下面的6个问题,那么你可以不用看这篇文章了



  1. 为什么Cleanup Stack有3个不同的PushL函数?

  2. 为什么CBase有public的析构函数

  3. CBase是怎么让它的子类初始化为0的

  4. 为什么要初始化为0

  5. 为什么不建议用new[]初始化CBase的继承类

  6. 为什么CBase有private 的拷贝构造函数和private的"="重载



下面是这6个问题的答案:



  1. Cleanup Stack可以保证出现异常时被压栈的对象成功释放内存。释放内存的方法有2种,调用delete(将调用析构函数)或者调用User::Free()。对于TAny指针指向的内容,Cleanup Stack在退出时候将仅调用User::Free(),这个时候需要用PushL(TAny*)。通常的CBase对象,则调用delete,这个时候用PushL(CBase*)。如果需要压入Cleanup Stack,又不想用CBase,则使用PushL(TCleanupItem)。

  2. 因为需要被Cleanup Stack调用,所以应该是public,因为多态的需要,应该是virtual。

  3. CBase重载了new函数,调用AllocZL分配内存,自然会初始化为0

  4. 继承自CBase的类被压栈后即使出现异常也能保证析构函数被调用。那么,如果它有一个成员变量是一个指针,在析构时需要根据这个指针是否NULL判断是否需要回收这个指针指向的内存,如果这个指针没有被初始化,在运行过程中发生异常,那么析构的时候这个指针就是野指针,删除它会让程序崩溃的。看一段代码就明白了。
    CTest* CTest::NewLC()
    {
    CTest* self = new ( ELeave ) CTest;
    CleanupStack::PushL( self );
    self->ConstructL()
    return self;
    }

    void CTest::ConstructL()
    {
    iPointer = CMustLeave::NewL(); // assume this leaves
    }

    CTest::~CTest()
    {
    if( iPointer )
    {
    delete iPointer;
    iPointer = NULL;
    }
    }
    如果iPointer没有初始化为NULL,则通过Cleanup Stack析构时可能导致程序崩溃。


  5. CBase并没有重装new[],如果使用new[]创建CBase的继承类对象,CBase的new重载函数则没有被调用,自然不会初始化CBase对象为0。如果需要创建对象的数组,可以用RPointerArray。

  6. 保证不被隐式的拷贝,你不能写诸如下面的代码
    CBase* pointer = new ( ELeave ) CBase;
    CBase base = *pointer; // call copy constructor


    编译器会报错



    CBase* pointer = new ( ELeave ) CBase;
    CBase base;
    base = *pointer; // call operator =


    这样防止的不被注意的浅拷贝问题,如果需要一个深拷贝函数,可以实现一个自己的public克隆函数例如CloneL()







Technorati : ,
Del.icio.us : ,

Monday, June 18, 2007

Perl下如何安装一个模块和使用smtp发送邮件

Active Perl和Cpan的Perl有些不一样,安装的时候使用ppm,具体的操作即在命令行模式下运行ppm

启动ppm后使用命令search xxx 模块名搜索模块,如果网络连接正常,过会就会返回找到的模块名称,我前面找的是sasl。
找到后运行 install authen-sasl,active perl会自动下载需要的文件并完成安装,看到Successfully installed authen-sasl version 2.10 in ActivePerl 5.8.3.809.
即成功完成安装。
下面是发送smtp邮件的方法
use Net::SMTP;
my $MailHost = "mailhost";
my $MailFrom = "xxxx\@mailhost.com";
my $MailTo = "xxxx\@mailhost.com";
my $subject = "Subject Line here";
my $MailBody = "This is the mail body";
my $smtp = Net::SMTP->new($MailHost) or die "Can't create smtp!";
$smtp->auth('user','pass');
# Send the From and Recipient for the mail servers that require it$smtp->mail($MailFrom); $smtp->to($MailTo);
# Start the mail$smtp->data();
# Send the header. $smtp->datasend("To: $MailTo\n"); $smtp->datasend("From: $MailFrom\n"); $smtp->datasend("Subject: $subject\n"); $smtp->datasend("\n");
# Send the message $smtp->datasend("$MailBody\n\n");
# Send the termination string $smtp->dataend();
$smtp->quit;

Sunday, June 17, 2007

使用winrar做备份

命令行如下

首先将rar命令行工具的路径添加到path中去
path=%path%;"RAR_PATH";
接着转到工作目录下
cd c:\project
运行rar,附带一下参数
rar a -r -agyyyy-mm-dd-hh-mm-ss bak test
这个命令行参数的意义是,a 代表添加到一个压缩文档, -r代表压缩的时候包括子目录,-agyyyy-mm-dd-hh-mm-ss代表在生成的压缩文档的名字后面加入一个时间,以yyyy-mm-dd-hh-mm-ss的格式,bak 为压缩文件的名字,结果会是bakyyyy-mm-dd-hh-mm-ss.rar,test是指定要压缩的目录或者文件名。

把上面的压缩脚本放入一个bat文件,然后用windows计划任务,就可以每周自动按时备份了:)