Sunday, March 24, 2013

Windows DLL Explicit Linking

Explicit Linking

The harder way to load a DLL is a little bit more complicated. You will need function pointers and some Windows functions. But, by loading DLLs this way, you do not need the .lib or the header file for the DLL, only the DLL. I'll list some code and then explain it.
 Find more about DLL from here
  1. #include <iostream>
  2. #include <windows.h>
  3.  
  4. typedef int (*AddFunc)(int,int);
  5. typedef void (*FunctionFunc)();
  6.  
  7. int main()
  8. {
  9. AddFunc _AddFunc;
  10. FunctionFunc _FunctionFunc;
  11. HINSTANCE hInstLibrary = LoadLibrary("DLL_Tutorial.dll");
  12.  
  13. if (hInstLibrary)
  14. {
  15. _AddFunc = (AddFunc)GetProcAddress(hInstLibrary, "Add");
  16. _FunctionFunc = (FunctionFunc)GetProcAddress(hInstLibrary,
  17. "Function");
  18.  
  19. if (_AddFunc)
  20. {
  21. std::cout << "23 = 43 = " << _AddFunc(23, 43) << std::endl;
  22. }
  23. if (_FunctionFunc)
  24. {
  25. _FunctionFunc();
  26. }
  27.  
  28. FreeLibrary(hInstLibrary);
  29. }
  30. else
  31. {
  32. std::cout << "DLL Failed To Load!" << std::endl;
  33. }
  34.  
  35. std::cin.get();
  36.  
  37. return 0;
  38. }

Thursday, March 7, 2013

Yum Install from ISO or DVD

yum (Yellow dog Updater Modified) is a package manager for RPM compatible Linux systems such as CentOS, Fedora core and latest Redhat Enterprise Linux.
So how do you use yum to update / install packages from an ISO of CentOS / FC / RHEL CD?
Creation of yum repositories is handled by a separate tool called createrepo, which generates the necessary XML metadata. If you have a slow internet connection or collection of all downloaded ISO images, use this hack to install rpms from iso images.

Step # 1: Mount an ISO file

Type the following command (replace iso file name with the actual iso file):
# yum install createrepo
# mkdir -p /mnt/iso/{1,2,3}
# mount -o loop /path/to/centos1.iso /mnt/iso/1

Step # 2: Create a repository

Use createrepo to generate the necessary XML metadata. Type the following commands:
# cd /mnt/iso
# createrepo .

Clean repo, enter:
# yum clean all

Step # 3: Create config file

You need to create a repo config file in /etc/yum.repos.d/ directory.
# vi /etc/yum.repos.d/iso.repo
Append following text:
[My ISO Repository]
baseurl=file:///mnt/iso
enabled=1

Save and close the changes.
Now use yum command to install packages from ISO images:
# yum install package-name