Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 362729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:16:29+00:00 2026-05-12T13:16:29+00:00

After trying many and searching web option to compile and load dll I could

  • 0

After trying many and searching web option to compile and load dll I could not able to create dll for tcl. Can you explain me how to do this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T13:16:30+00:00Added an answer on May 12, 2026 at 1:16 pm

    Ok, here is a simple example. This code compiles and works for Tcl8.5 and VS2008. To start with I created a WIN32 dll project called BasicTclExtn that exported symbols.

    // BasicTclExtn.h
    #ifdef BASICTCLEXTN_EXPORTS
    #define BASICTCLEXTN_API __declspec(dllexport)
    #else
    #define BASICTCLEXTN_API __declspec(dllimport)
    #endif
    
    int BasicExtnCmd(ClientData data, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) ;
    extern "C" {
        BASICTCLEXTN_API int Basictclextn_Init(Tcl_Interp *interp) ;
    }
    

    And then the .cpp file

    // BasicTclExtn.cpp : Defines the exported functions for the DLL application.
    #include "stdafx.h"
    #include "BasicTclExtn.h"
    
    int
    BasicExtnCmd(ClientData data,
                 Tcl_Interp *interp,
                 int objc,
                 Tcl_Obj *CONST objv[])
    {
    
        // Check the number of arguments
        if (objc != 3) {
            Tcl_WrongNumArgs(interp, 1, objv, "arg arg");
            return TCL_ERROR;
        }
    
        long v1, v2, result ;
    
        if ( Tcl_GetLongFromObj(interp, objv[1], &v1) != TCL_OK)
            return TCL_ERROR ;
    
        if ( Tcl_GetLongFromObj(interp, objv[2], &v2)  != TCL_OK)
            return TCL_ERROR ;
    
        result = v1 + v2 ;
    
        Tcl_SetObjResult(interp, Tcl_NewIntObj(result)) ;
            return TCL_OK ;
    }
    
        // Note the casing on the _Init function name
        BASICTCLEXTN_API int Basictclextn_Init(Tcl_Interp *interp)
        {
            // Link with the stubs library to make the extension as portable as possible
            if (Tcl_InitStubs(interp, "8.1", 0) == NULL) {
                return TCL_ERROR;
            }
    
            // Declare which package and version is provided by this C code
            if ( Tcl_PkgProvide(interp, "BasicTclExtn", "1.0") != TCL_OK ) {
                return TCL_ERROR ;
            }
    
            // Create a command
            Tcl_CreateObjCommand(interp, "BasicExtnCmd", BasicExtnCmd, (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
    
            return TCL_OK ;
        }
    

    You need to #include tcl.h in the stdafx.h.

    This example uses the Tcl stubs facility, see the documentation on the Tcl_InitStubs function for more information; when using stubs you need to link to only the tclstub85.lib. To get the code to link properly you need to do the following:

    • Add the include directory where tcl.h is installed to Configuration Properties -> C/C++ -> General -> Additional Include Directories
    • Define the USE_TCL_STUBS symbol, I normally do this in Properties-> C/C++ -> Preprocessor -> Preprocessor Definitions. You may also find that you then need to define the <DLLNAME>_EXPORTS (BASICTCLEXTN_EXPORTS in my example) after this, I’m not sure why this happens.
    • Add the path to the directory where the tclstub85.lib file is as an additional library directory in Configuration Properties -> Linker -> General -> Additional Library Directories.
    • Add tclstub85.lib to Configuration Properties -> Linker -> Input -> Additional Dependancies
    • If the compiler spits out a warning about MSVCRT then exclude MSVCRT by adding it to the ignored libraries in Configuration Properties -> Linker -> Input -> Ignore Specific Library.

    All of these .lib, .dll and .h files should be easily found in your Tcl installation. You’ll also need to ensure that the related tclstub85.dll and tcl85.dll can be found at run time, making sure the bin directory for Tcl is on the PATH should sort that out. So you should then be able to do the following from Tcl:

    C:\Projects\BasicTclExtn\Debug>tclsh
    % load BasicTclExtn.dll
    % BasicExtnCmd 1 2
    3
    % BasicExtnCmd 1 2.p
    expected integer but got "2.p"
    % BasicExtnCmd 1 2
    3
    % BasicExtnCmd 1
    wrong # args: should be "BasicExtnCmd arg arg"
    % BasicExtnCmd 1 3
    4
    % exit
    

    This is the simplest form of Tcl exstention, you can add additional calls to Tcl_CreateObjCommand() to add more commnds into this extension. Tcl provides some faciities to help with the processing of the command line paramters passed into the command. The example code used Tcl_WrongNumArgs() but you should also look at the Tcl_GetIndexFromObj() functions.

    I would also suggest you get a copy of Practical Programming in Tcl and Tk by Brent Welch. You can read some sample chapter here http://www.beedub.com/book/, the chapter on C programming for Tcl from the 3rd edition will help you a lot.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am facing a small issue which i am not able after trying so
I'm trying to start unicorn_rails in a ruby script, and after executing many commands
After trying a lot i decided to ask question on stackoverflow, I create a
I am trying to find any comments created after a datetime that were not
After trying to work on someone else's code, and so many different iterations, I
I just finally after trying many time over the past few years, got my
I'm not sure if this is even possible after trying to figure it out
I've been working on a doodling app recently just for kicks. After trying many
After many hours spent on reading documentations and searching for some tips on the
I know this is a repetitive question, but after searching for many similar questions

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.