NO

Author Topic: Experienced developer new to C  (Read 9276 times)

MT

  • Guest
Experienced developer new to C
« on: May 07, 2008, 09:58:29 PM »
Hello All,
I have been developing commercially for the last ten years in a VB like language.

I am constantly frustrated by the fact that every DLL I want to utilize is has source available in C that I cannot get my head around.

Recently I wanted to work with 7z. There was no 32bit DLL available, only activeX. So then I was faced with the prospect of compiling one. God knows where to start with that.

Then I found one, compiled by a Japanese guy, so all everything was in Japanese!
I managed to figure out what all the exported functions from the DLL were (with a tool I wrote) then I had the dilemma of trying to figure out what the arguments to these functions might need.

So I am back to the problem of reading C code again. If i could find the functions in the code, I could probably deduce what they are, but the project is huge:
http://www.7-zip.org/sdk.html

So here I am. I can read Java and pascal somewhat, so I think I can manage C, but all these switches and libraries and linkers and arrrrrrrgh... how do I find the wood for the trees in this language?

For Example, How do I find the the functions:
FUNCTION SevenZipExtractMem             LIB "7-ZIP32.DLL" ALIAS "SevenZipExtractMem"            ( BYVAL hWnd AS LONG, BYVAL szCmdLine AS STRING, BYREF lpBuffer AS BYTE, BYVAL dwsize AS LONG, lpTime AS LONG, lpwAttr AS STRING, lpdwWriteSize AS LONG) AS LONG

FUNCTION SevenZipCompressMem            LIB "7-ZIP32.DLL" ALIAS "SevenZipCompressMem"           ( BYVAL hWnd AS LONG, BYVAL szCmdLine AS STRING, BYREF lpBuffer AS BYTE, BYVAL dwsize AS LONG, lpTime AS LONG, lpwAttr AS STRING, lpdwWriteSize AS LONG) AS LONG

In the C code?

Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 582
    • Homepage
Re: Experienced developer new to C
« Reply #1 on: May 08, 2008, 01:13:29 AM »
How about using the command line executable instead of the DLL, it is easier to handle from any BASIC language.
---
Stefan

Proud member of the UltraDefrag Development Team

MT

  • Guest
Re: Experienced developer new to C
« Reply #2 on: May 08, 2008, 08:43:22 AM »
Well because I am actually embedding the Dll and creating a communication Dll.
Apart from that, I run into this more often than i would like and I just need to learn how to read and/or compile a DLl from C code.

Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 582
    • Homepage
Re: Experienced developer new to C
« Reply #3 on: May 08, 2008, 10:22:04 AM »
The header files (.h) contain the declarations and definitions of the functions, types, structures and constants.
The source files (.c) contain the actual code.
The compiler finds the header files through the #include directive of the source files.

The functions in question will be located in a source file as:
int ... SevenZipExtractMem(...)
{
...
}
---
Stefan

Proud member of the UltraDefrag Development Team

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Experienced developer new to C
« Reply #4 on: May 08, 2008, 05:58:52 PM »
http://downloads.sourceforge.net/sevenzip/lzma458.tar.bz2
Quote
For Example, How do I find the the functions:
I can't find those functions from that codetree.

Example to compile 7zDec.exe and lzma.dll :

Extract or copy dir C to new dir 7z\C for PellesC
Copy 7z\CPP\7zip\MyVersion.h to new 7z\CPP\7zip\
Copy 7z\CPP\7zip\MyVersionInfo.rc to new 7z\CPP\7zip\
Copy 7zDec.ppj to new 7z\C\Archive\7z\
Copy LzmaDll.ppj to new 7z\C\LzmaLib\

LZMA.dll:
EXPORTS
  LzmaCompress
  LzmaUncompress

Code: [Select]
Declare Function LzmaCompress Lib "LZMA.dll" Alias "LzmaCompress" (ByVal dest as Long, ByVal destLen as Long, ByVal src as Long, ByVal srcLen as Long, ByVal outProps as Long, ByVal outPropsSize as Long, ByVal level as Long, ByVal dictSize as Long, ByVal lc as Long, ByVal lp as Long, ByVal pb as Long, ByVal fb as Long, ByVal numThreads as Long) As Long
Declare Function LzmaUncompress Lib "LZMA.dll" Alias "LzmaUncompress" (ByVal dest as Long, ByVal destLen as Long, ByVal src as Long, ByVal srcLen as Long, ByVal props as Long, ByVal propsSize as Long) As Long

Actual C defines:
Code: [Select]
MY_STDAPI LzmaCompress(unsigned char * dest, size_t * destLen, const unsigned char * src, size_t srcLen, unsigned char * outProps, size_t * outPropsSize, int level, unsigned dictSize, int lc, int lp, int pb, int fb, int numThreads);
MY_STDAPI LzmaUncompress(unsigned char * dest, size_t * destLen, const unsigned char * src, size_t * srcLen, const unsigned char * props, size_t propsSize);
I hope this helps you
May the source be with you

MT

  • Guest
Re: Experienced developer new to C
« Reply #5 on: May 26, 2008, 09:08:43 AM »
OK you are right. I need to create a 32bit DLL with these functions as described here:
http://www.eggheadcafe.com/tutorials/aspnet/064b41e4-60bc-4d35-9136-368603bcc27a/7zip-lzma-inmemory-com.aspx

« Last Edit: May 29, 2008, 07:34:06 AM by MT »

MT

  • Guest
Re: Experienced developer new to C
« Reply #6 on: May 29, 2008, 08:43:59 AM »
Timovjl,

Thank you so much for posting that. I think I have just understood that you have compiled a 32bit Dll with two exported functions.
LzmaCompress
LzmaUncompress

I am trying to duplicate this by following your directions in the hope that I can compile my first Dll!

I am assuming that copying C dir from the download of the source for 4.58 beta ?
http://www.7-zip.org/sdk.html

to the folder:
C:\Documents and Settings\UserName\My Documents\Pelles C Projects\7z ?

Then I copied the files you posted to the appropriate folders and launched the compiler.

I see a list of files on the right (code tree?) and diamonds underneath them that I assume are the functions within the file?

When I try to compile i get the error message:
Don't know how to make "C:\Documents and Settings\UserName\My Documents\Pelles C Projects\7z\C\LzmaUtil\LzmaLibExports.c".

I guess it cant find this file?

Does the compiler list ALL the missing files at once or does list the first one it cannot find and then exit? (ie will i find another missing file after this one is sourced)

Added:
Ok I deleted and added two files the compiler could not find, so now it sees them.
Now I get teh compile error:
fatal error: File not found: 'C:\Documents and Settings\UserName\My Documents\Pelles C Projects\7z\C\LzmaUtil\resource.rc'.

Where is this file supposed to be?
perhaps in ...Pelles C Projects\7z\CPP\ ?

If I right click on the file and select properties, the path gets truncated at the edge of the window before I can read it all! (the window is not resizable)
Is there another way to see the path ?



« Last Edit: May 29, 2008, 09:00:14 AM by MT »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Experienced developer new to C
« Reply #7 on: May 29, 2008, 10:00:26 AM »
Quote
Where is this file supposed to be?
Same directory as in original source tree.
.\C\LzmaUtil\resource.rc

I attached source tree in that 7z.zip file for testing.

May the source be with you