Web development by PHP-Web-Host.com   Website Hosting by PHP-Web-Host.com
Web Hosting by PHP-Web-Host.com

SoftSmart Blogs!

SoftSmart Technical, Software and Web Related Blogs

Tel (Lon, UK): 020 8133 3460

 

 

Blogs

Archive for February, 2010

Compiling a C++ dll with MinGW to use with Visual Basic

Tuesday, February 16th, 2010

Using a dll compiled with C++ in visual basic is really rather easy, its just a little hard to find good (EASY) information of how to do it. There is a fair amount of information for Microsoft’s C++ compilers, but what about us who write in a text editor and compile with g++ on MinGW? This post will show you how you can be using a c++ dll in visual basic.

I’m a big fan of ANSI C++, MinGW and the g++ compiler. I don’t like MS C++ compilers for various reasons. One of those is that I don’t believe it generates ANSI compliant code, and I certainly can’t compile for Linux from it.

If you are a visual basic (VB) coder, it may be necessary at times to use a dll compiled in C++. Or, you may be in a similar situation to myself: all of your projects are written in VB and you are porting everything over to C++. However, you have a problem. Porting everything at once will take a long time. If you port a module to C++, you would want to start using that module straight away with your existing VB projects (until you have ported the whole lot).

So, here is a quick guide on accomplishing that. This guide is very simple and is intended to get you started in the right direction.

Create a cpp file called “test.cpp”. In this file, paste the following code:

// Start of file

extern “C” // only required if using g++
{

__declspec (dllexport) int __stdcall FooBar (void)
{
return 343;
}

__declspec (dllexport) int __stdcall TimesTwo (int val)
{
return val * 2;
}

}

// end of file

Now we need to compile our dll. There are two steps (maybe they can be converted into a single step, but as I said, this is a beginners guide and I’m not an expert (yet) on the g++ compiler).

To compile, in MinGW, cd to the directory that has your cpp file and type:

g++ -c -Dtest_dll test.cpp

This will create a file called test.o

Now type

g++ -shared -o test.dll test.o -Wl,–add-stdcall-alias

This will create test.dll

Now, open a normal VB  project and in the form’s code space, paste the following

Option Explicit

Private Declare Function FooBar Lib “C:\msys\1.0\home\John\Dll_with_VB_test\test.dll” () As Integer
Private Declare Function TimesTwo Lib “C:\msys\1.0\home\John\Dll_with_VB_test\test.dll” (ByVal val As Integer) As Integer

Private Sub Form_Load()

Debug.Print FooBar

Debug.Print TimesTwo(5)

End Sub

Take note of two things here:

1) The path to the dll must obviously be changed to be correct on your system

2) In the second declare, we pass an integer called val in to the dll. If you leave out the ByVal, the value is corrupted, so the ByVal bit is important.

That’s it, please post back here if you have any useful insights. Lets learn (and port our software) together!

 


 

Using Alt Tags in Images

Tuesday, February 2nd, 2010

This is a quick note about alt tags.

Please see this article for more info: Can google see your website?

The reason I’m writing this again is because of its importance, but more importantly because of how many people do not do this.

Imagine you’re sitting in a movie theather, 60 / 70 years ago. Movies have not yet advanced to a stage where there is sound, so its a silent movie. Not very nice hey? And to make matters worse, you’ve brought your blind friend with you.

So, what has this got to do with the search engines. Well, you need to think of your website as an old fashioned movie with no sound. And you need to think of Google as your blind friend. He can’t see anything, and, as there is no sound in the movie, he can’t hear anything. Besides the pop corn, its really a waste. He needs to read braille.

Images on your website are like that silent movie. Google, being blind, needs the braille of the web, that is, it needs plain text! If you have a website with loads of images that look really great to visitors, remember, your blind friend google can’t read them (or the other search engines).

So, what should you do? Provide Alt text in images.

Here is an INCORRECT image tag <img src=”someimage.jpg”>.

Here is a CORRECT image tag <img src=”someimage.jpg” alt=”Yay, google can read this!”>

Ok, so, a demonstration is in order. Now, lets see an example, then you can rush off and try this on your own site. We are going to work with three php files:

1) image_noalt.php which has only an image as the main body. This image has NO alt text. So, this page is very bad and google can’t index it correctly. What about the meta keywords tags? Look here, google DOES NOT USE THEM, or look here! Matt Cutts is a chief engineer from Google. If I have his title incorrect, please forgive me, I don’t work there, I don’t know who gets called what, I just know that he’s a pretty important person there!

2) image_alt.php. This page has the same image, but it DOES have alt text, so google can “read” what your image is about, and can thus index it.

3) split.php. Here we have split this image. We have kept the heading as an image because we wanted the cool shadow effect (which you can probably do with some clever CSS anyway). The header image has alt text. Then, for the two smaller images, we’ve made their titles plain text, so google can index that. We’ve also added alt text to both the smaller images, so google has 5 pieces of information here.

To see what google more or less sees with these files, we’ll do a little comparison.

Below we have three examples. One is a page with NO ALT tags, and the entire page is just an image. There is a clickable link so you can see what the page looks like visually. Next to the clickable link, after the | symbol, is a link you need to copy and paste into a web browser. This will show you how google sees the page.  Do that for each of the three examples below. Note that when you copy the second link to see how google sees your page, you will notice some banners at the top. Those are advertising banners put there by that company. We are just looking at the text parts which is what google sees.

1) Normal image_noalt.php | http://www.delorie.com/web/lynxview.cgi?url=http://www.softsmart.co.za/blog/image_noalt.php

  • Note here that the image name big_image.jpg is all that is visible to google, in terms of the main body text, not good at all

2) Normal image_alt.php | http://www.delorie.com/web/lynxview.cgi?url=http://www.softsmart.co.za/blog/image_alt.php

  • Here there is alt text that is visible to google, so it is an improvement

3) Normal split.php | http://www.delorie.com/web/lynxview.cgi?url=http://www.softsmart.co.za/blog/split.php

  • Here there is alt text ON EACH images, as well as plain text that is visible to google, this is the best way of making sure that google know’s what your site is about.

Conclusion

If you use image, use alt text. Always! No exceptions! If you are able to split the image up, then do that. Use plain text where possible.

 


 

Get Adobe Flash playerPlugin by wpburn.com wordpress themes

 

 

We accept PayPal

 

Web Hosting by PHP-Web-Host.com Website Hosting by PHP-Web-Host.com

[ Home ] | [ Software ] | [ Web Development ] | [ Resources ] | [ Contact ] | [ Privacy Policy ] | [ Acceptable Use Policy ] | [ Terms of Service ] | [ Sitemap ] | [ Clients ] | [ Affiliates ]

[ PHP Web Hosting ] | [ Linux Web Hosting ] | [ 500mb PHP Web Hosting ] | [ 1Gb PHP Web Hosting ] | [ 3Gb PHP Web Hosting ] | [ 6Gb PHP Web Hosting ] | [ 10Gb PHP Web Hosting ]

[ HTML Tutor ] | [ CSS Tutorial ] |