• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 231
  • Last Modified:

How to export the c-programmes?

I have a routine written in the c-programming lang which returns a string or value as a result. I want to provide interface to this routine using VB/VC++ so that when I press a button it should execute c programme i.e written, and should display the result in the dialog box. I know that for that c routine has to to "Publicly EXPORTED", but I don't how to do this? Please Help.
  • 2
  • 2
1 Solution
arvindhpAuthor Commented:
If possible give the C-code.
2 solutions are possible:
Write a DLL
or use COM/DCOM
If your program realy is a C program (not C++) COM/DCOM is verry hard to implement.
So in this case I would recommend the DLL solution.
As I know - until now I did not myself - the C Function has to be declared with calling convention stdcall and as exportable like
Inside *.C/*.H file
__declspec( dllexport ) YourReturnType  __stdcall YourFunction(YourParameter1Type Parameter1,...);
/*... for other parameters not for variable arguments*/
now the function - if compiled and linked without errors - is ready for external use:
from VC you need the header that declares
__declspec( dllimport ) YourReturnType  __stdcall YourFunction(YourParameter1Type Parameter1,...);
and the *.lib file that is generated by the linker or

from VB you need to declare the function like
Public Declare YourFunction  Lib "YourLib" (Parameter1 as YourParameterType1,...) as YourReturnType

arvindhpAuthor Commented:
I have got only Turbo C++ compiler and VB with me(please assume). __stdcall and __export__ is not available with this compiler. Is there any other method available to do this kind of operation. If yes please give the method as well as code.
First of all if an answer does not satisfy you or in this case seems not work for you you should not accept it.
if you accept it it is stored inside the previous asked question section an no other expert is able to answer you.
You have Turbo C - what you did not say - I have Visual C and no expirience with Turbo C. But I will try to help. may be you can figure out your self what you have to do if you got further information
First of all is the version of Turbo C able to build DLL's ?
if not you have no chance to do what you want.
if yes try to figure out how to export a function may be you have to use a *.def file - use online help keyword may be export(ing Functions from DLL)
I can show you what microsoft tells about stdcall calling convention
From the online help:
/* Start of text*/
Microsoft Specific ®

The __stdcall calling convention is used to call Win32 API functions. The callee cleans the stack, so the compiler makes vararg functions __cdecl. Functions that use this calling convention require a function prototype. The following list shows the implementation of this calling convention.

Element                                            Implementation
Argument-passing order                    Right to left.

Argument-passing convention          By value, unless a pointer or reference type is passed.

Stack-maintenance responsibility     Called function pops its own arguments from the stack.

Name-decoration convention           An underscore (_) is prefixed to the name. The name is followed by the at sign (@) followed by the
                                                        number of bytes (in decimal) in the
                                                        argument list. Therefore, the function declared as int func( int a,
                                                        double b ) is decorated as follows: _func@12

Case-translation convention            None
Functions declared using the __stdcall modifier return values the same way as functions declared using __cdecl.

END Microsoft Specific
/*End of text*/
with this information you may be able to use borland online help to figure out how to declare the functions that VB can find them.
Keyword Calling convention
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now