SDS Example Get/ SetClipboardText

Topics relating to AutoLisp and SDS.

Moderators: CMS Inc, avaernes

Post Reply
Danielm103
Valued Contributor
Posts: 54
Joined: Mon Aug 07, 2006 11:01 pm
Location: Albuquerque,NM,USA

SDS Example Get/ SetClipboardText

Post by Danielm103 » Wed Aug 29, 2007 11:56 am

I know there are not a lot of samples out there on the net for writing SDS functions.
Here is a SDS routine , that when loaded will enable lisp to Set/Get text to/from the clipboard. Enjoy.

PS. If you have any questions about SDS or would like me to email the compiled .dll to you, just ask.

Code: Select all

 
/* ++
 * SDSs.C © 2007, Daniel Marcotte
 * Intellicad SDS Addon -- SetClipboardText GetClipboardText
 * for lisp
 * Party On!
 * SetClipboardText (SetClipboardText "How yuz doin'")
 * GetClipboardText (GetClipboardText)
 *                                                       -- */
//////////////////////////////////////////////////////////////////////
//Includes
//////////////////////////////////////////////////////////////////////
#include <windows.h>
#include <stdio.h>
#include <sds.h>
#include <TCHAR.h>
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
#define INIBUFFSIZ 8192
#define WIN32_LEAN_AND_MEAN
#define ARRAYELEMENTS(array) (sizeof(array)/sizeof((array)[0]))
#define DllExport __declspec(dllexport)

#ifdef UNICODE
#define CF_TCHAR CF_UNICODETEXT
#else
#define CF_TCHAR CF_TEXT
#endif
//////////////////////////////////////////////////////////////////////
//Protos
//////////////////////////////////////////////////////////////////////
int funcload(void);
void funcunload(void);
int dofun(void);
int SDS_GetGlobals(TCHAR *appname, HWND * hwnd, HINSTANCE * hInstance);
void DllExport SDS_EntryPoint(HWND hWnd);
int SetClipboardText(void);
int GetClipboardText(void);

#pragma region EntryPoint
//////////////////////////////////////////////////////////////////////
//Variables
//////////////////////////////////////////////////////////////////////
TCHAR adsw_AppName[512];
TCHAR *sds_argVec = adsw_AppName;
TCHAR sds_appname[512];
HWND adsw_hwndAcad;
HINSTANCE adsw_hInstance;
HWND adsw_hWnd;
int adsw_wait;
sds_matrix sds_identmat;

//struct   
typedef struct {
    TCHAR *func_name;
    int (*func) (void);
} func_def;

// Put your function names here
static func_def func_table[] = {
    {_T("SetClipboardText"), SetClipboardText},
    {_T("GetClipboardText"), GetClipboardText}
};
//////////////////////////////////////////////////////////////////////
//SDS Main
//////////////////////////////////////////////////////////////////////
int SDS_main(int argc, TCHAR **argv)
{
    short scode = RSRSLT;
    int stat;
    TCHAR errmsg[80];
    sds_init(argc, argv);
    for (;;)
    {
        if ((stat = sds_link(scode)) < 0)
        {
            sprintf(errmsg, _T("sds_link() Failed = %d\n"), stat);
            sds_printf(errmsg);
            sds_exit(-1);
        }
        scode = RSRSLT;
        switch (stat)
        {
            case RQXLOAD:
            {
                scode = (short)(funcload() == RTNORM ? RSRSLT : RSERR);
            }
                break;
            case SDS_RQXUNLD:
                funcunload();
                break;
            case RQSUBR:
            {
                scode = (short)(dofun() == RTNORM ? RSRSLT : RSERR);
            }
                break;
            case SDS_RQSAVE:
                break;
            case SDS_RQEND:
                break;
            case SDS_RQQUIT:
                break;
            case SDS_RQCFG:
                break;
            case SDS_RQHUP:
                break;
            case SDS_RQXHELP:
                break;
            default:
                break;
        }
    }
}
//load
int funcload(void)
{
    for (short i = 0; i < ARRAYELEMENTS(func_table); i++)
    {
        if (!sds_defun(func_table[i].func_name, i))
            return RTERROR;
    }
    return RTNORM;
}
//Unload
void funcunload(void)
{
    for (short i = 0; i < ARRAYELEMENTS(func_table); i++)
    {
        ads_undef(func_table[i].func_name, i);
    }
}
//Run function
int dofun(void)
{
    int val, rc;
    val = sds_getfuncode();
    if (val < 0 || ARRAYELEMENTS(func_table) <= val)
    {
        sds_fail(_T("Failed"));
        return RTERROR;
    }
    rc = (*func_table[val].func) ();
    return rc;
}
//////////////////////////////////////////////////////////////////////
//Entry Point
//////////////////////////////////////////////////////////////////////
void DllExport SDS_EntryPoint(HWND hWnd)
{
    for (int i = 0; i <= 3; i++)
        for (int j = 0; j <= 3; j++)
            sds_identmat[i][j] = 0.0;
    for (int i = 0; i <= 3; i++)
        sds_identmat[i][i] = 1.0;

    SDS_GetGlobals(adsw_AppName, &adsw_hwndAcad, &adsw_hInstance);
    strncpy(sds_appname, adsw_AppName, sizeof(sds_appname) - 1);
    SDS_main(1, &sds_argVec);
    return;
}
#pragma endregion

#pragma region ClipboardText
//(SetClipboardText "How yuz doin'")
int SetClipboardText(void)
{
    TCHAR Buf[INIBUFFSIZ];
    struct resbuf *pArgs = sds_getargs();
    if (pArgs == NULL && pArgs->restype != RTSTR)
        return RSERR;
    _tcscpy(Buf, pArgs->resval.rstring);
    if (!OpenClipboard(NULL))
        return RSERR;
    HGLOBAL hglClipBuff;
    TCHAR *pszBuf;
    EmptyClipboard();
    hglClipBuff = GlobalAlloc(GMEM_MOVEABLE, (_tcslen(Buf) + 1) * sizeof(TCHAR));
    pszBuf = (TCHAR *)GlobalLock(hglClipBuff);
    _tcscpy(pszBuf, Buf);
    GlobalUnlock(hglClipBuff);
    SetClipboardData(CF_TCHAR, hglClipBuff);
    CloseClipboard();
    sds_rett();
    return (RSRSLT);
}

//(GetClipboardText)
int GetClipboardText(void)
{
    TCHAR *pszBuf;
    TCHAR *pszStrout;
    HGLOBAL hglClipBuff;
    if (!OpenClipboard(NULL))
        return RSERR;
    if ((hglClipBuff = GetClipboardData(CF_TCHAR)) != NULL)
    {
        pszStrout = (TCHAR *)GlobalLock(hglClipBuff);
        pszBuf = (TCHAR *)sds_malloc(GlobalSize(hglClipBuff));
        if (pszBuf == NULL)
            return RSERR;
        _tcscpy(pszBuf, pszStrout);
        GlobalUnlock(hglClipBuff);
    }
    CloseClipboard();
    if (pszBuf == NULL)
        return RSERR;
    sds_retstr(pszBuf);
    sds_free(pszBuf);
    pszBuf = NULL;
    return (RSRSLT);
}
#pragma endregion


[/code]
AJS
Contributor
Posts: 10
Joined: Tue Feb 10, 2009 11:54 am

Post by AJS » Fri May 01, 2009 5:47 pm

Daniel,

If you by any chance still have the compiled .dll available, it would work great for me.


---Thanks


AJS
Danielm103
Valued Contributor
Posts: 54
Joined: Mon Aug 07, 2006 11:01 pm
Location: Albuquerque,NM,USA

Post by Danielm103 » Sat May 02, 2009 4:44 am

Sure, try getting it from here
http://www.intellicad.net/forum/topics/ ... s-for-lisp

there should be some other goodies in the dll too
AJS
Contributor
Posts: 10
Joined: Tue Feb 10, 2009 11:54 am

Post by AJS » Sun May 03, 2009 3:11 pm

Thank you very much!
Post Reply