The LIB file generated by using forged DLL in C ++ builder can call the DLL written by VC normally.

Source: Internet
Author: User

Introduction: "The method dynamically called in C ++ Builder6 (static call test fails, mainly because implib cannot generate correct pinyin. lib: the file name is missing. When the file is started, it is reported that the file cannot be found. I don't know who can help solve this problem )".

When I wrote "get the first letter of Chinese pinyin in Delphi 7", I tried to write the C ++ Builder 6 call example. Unfortunately, the static call was not successful at the time, the LIB file generated by implib with the Chinese path is different from the Lib file generated in the root directory (you can see it by using ultraedit), for example: "implib E: /pinyin initial/pinyin. lib E:/pinyin initials/pinyin. DLL "and" implib F:/pinyin. lib F:/pinyin. DLL "generated pinyin. lib is different. "E Corporation" cannot be found when the former is compiled and run. DLL ", and then access address error; the latter is not compiled directly, and the connection error" [linker Error] unresolved external 'getpinyinleader 'referenced from E:/ 文 /unit1.obj "is reported ".

I tried other methods to generate Lib, including directly modifying the binary file. Finally, I thought of a previous post saying that a DLL with an empty method body can be forged. The generated lib can directly call the DLL generated by VC.

The original statement is as follows: "lib can be fake. For example, if you use a function in vc dll to write a DLL using BCB, the same function is provided. The implementation is empty and then compiled.
For other projects that use DLL, link this Lib in Lib, and use the vc dll"

Reference: http://topic.csdn.net/u/20090302/17/99d1fbc5-4be6-4744-96d9-09b16c0d93c3.html

 

The help reference text of this pinyin library is as follows:

----------------------------------------------------------------------------

This dll has only two functions. The function prototype is as follows:

// Obtain pinyin
// The parameters are in sequence: pinyin cache, the characters to be converted, and the delimiters
Bool winapi getpinyin (pchar pbuf, pchar pstr, pchar extends parator)

// Obtain the first letter of the pinyin alphabet
// The parameters are in the pinyin cache area and the characters to be converted
Bool winapi getpinyinleader (pchar pbuf, pchar pstr)
Bytes -------------------------------------------------------------------------------------

 

 

The following is the counterfeit DLL code:

# Include <windows. h> <br/> # pragma argsused </P> <p> extern "C" _ declspec (dllexport) bool _ stdcall winapi getpinyinleader (pchar pbuf, pchar pstr ); <br/> extern "C" _ declspec (dllexport) bool _ stdcall winapi getpinyin (pchar pbuf, pchar pstr, pchar parser parator ); </P> <p> int winapi dllentrypoint (hinstance hinst, unsigned long reason, void * lpreserved) <br/>{< br/> return 1; <br/>}< br/>/<br/> bool _ stdcall winapi getpinyinleader (pchar pbuf, pchar pstr) <br/>{< br/> return true; <br/>}< br/> bool _ stdcall winapi getpinyin (pchar pbuf, pchar pstr, pchar character parator) <br/>{< br/> return true; <br/>}

 

Static call code:

 

Extern "C" _ declspec (dllimport) bool _ stdcall getpinyinleader (char * Buf, char * input); <br/> extern "C" _ declspec (dllimport) bool _ stdcall getpinyin (char * Buf, char * input, char * SP); <br/> // else <br/>__ fastcall tform1 :: tform1 (tcomponent * owner) <br/>: tform (owner) <br/>{< br/>}</P> <p> void _ fastcall tform1 :: btn1click (tobject * sender) <br/>{</P> <p> char cbuf [256] = {0}; <br/> memset (cbuf, 0, sizeof (cbuf); <br/> char * cinput; <br/> cinput = (TRIM (edt1-> text )). c_str (); <br/> // <br/> getpinyinleader (cbuf, cinput); <br/> edt2-> text = (ansistring) cbuf; </P> <p>}

After testing, the conclusion is: this can be done, and the result is the same as that of dynamic calling.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.