Ignore:
Timestamp:
Jul 12, 1999, 2:21:37 AM (26 years ago)
Author:
davidr
Message:

Updated clsid handling to correctly draw textual clsid's
Fixed GUID instansiation.
Moved initialisation to OLE32.CPP
Added many new APIs incl. CoCreateInstance & CoGetClassObject.
Many partially implemented stubs completed and moved to OLE32.CPP
Running Object Table implemented (Moniker.cpp)
IMalloc & Task Memory implemented.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/ole32/oString.cpp

    r201 r291  
    11
    2 #include <string.h>
    3 
    4 // Prevent CALLCONV becoming _System
    5 #include <winbase.h>
    6 #include <uconv.h>
    7 #undef CALLCONV
    8 
    9 #include <os2win.h>
     2#include "ole32.h"
    103
    114#include "oString.h"
    125
     6// ======================================================================
     7// oStringBase - Base stuff for oString classes
     8// ======================================================================
     9
    1310// Block size.
    14 long oStringA::blockSize = 32;
     11long oStringBase::blockSize = 32;
     12
     13// Initialise to nothing...
     14oStringBase::oStringBase(long bytePerChar)
     15{
     16    m_bytePerChar = bytePerChar;
     17    m_Heap = GetProcessHeap();
     18}
     19
     20// Destructor
     21oStringBase::~oStringBase()
     22{
     23    freeBuf();
     24}
    1525
    1626// calculate the buffersize needed for this string (quantised to blockSize)
    17 long oStringA::calcBufLen(long strLen)
     27long oStringBase::calcBufLen(long strLen)
    1828{
    1929    long        tmp;
    2030
    21     tmp = (strLen / blockSize) + 1;
     31    tmp = ((strLen * m_bytePerChar) / blockSize) + 1;
    2232
    2333    return tmp * blockSize;
     
    2535
    2636// Get a buffer of required length...
    27 void oStringA::getBuf(long strLen)
     37void oStringBase::getBuf(long strLen)
    2838{
    2939    // Sanity check...
    3040    if (strLen < 1)
    3141    {
    32         dprintf(("Warning: oStringA::getBuf - strlen < 1!"));
     42        dprintf(("oStringBase: Warning! ::getBuf - strlen < 1!"));
    3343        strLen = 1;
    3444    }
     
    4252
    4353// Free buffer...
    44 void oStringA::freeBuf()
     54void oStringBase::freeBuf()
    4555{
    4656    HeapFree(m_Heap, 0, m_strBuf);
     
    4858
    4959// Re-allocate buffer if more space is required...
    50 void oStringA::adjBuf(long strLen)
    51 {
    52     if (strLen > m_bufLen)
     60void oStringBase::adjBuf(long strLen)
     61{
     62    if ((strLen * m_bytePerChar) > m_bufLen)
    5363    {
    54         LPSTR   strBuf;
    5564        long    bufLen = calcBufLen(strLen);
    5665
    5766        // Allocate new buffer...
    58         strBuf = (LPSTR)HeapAlloc(m_Heap, 0, bufLen);
    59 
    60         // Copy old buffer to new...
    61         strcpy(strBuf, m_strBuf);       // Incl. terminator...
    62         freeBuf();
     67        m_strBuf = (LPSTR)HeapReAlloc(m_Heap, 0, m_strBuf, bufLen);
    6368
    6469        // Save new buffer...
    65         m_strBuf = strBuf;
    6670        m_bufLen = bufLen;
    6771    }
    6872}
    6973
     74// ======================================================================
     75// oStringA - String manipulation based on ASCII
     76// ======================================================================
     77
    7078// Initialise to nothing...
    71 oStringA::oStringA( void)
    72 {
    73     m_Heap = GetProcessHeap();
    74     getBuf(1);  // Incl. terminator...
     79oStringA::oStringA( void) : oStringBase(sizeof(char))
     80{
     81    getBuf( 1); // Incl. terminator...
    7582}
    7683
    7784// Initialise to a specified length...
    78 oStringA::oStringA(int defLen)
    79 {
    80     m_Heap = GetProcessHeap();
    81     getBuf(defLen + 1);
     85oStringA::oStringA(int defLen)   : oStringBase(sizeof(char))
     86{
     87    getBuf( defLen + 1);
    8288}
    8389
    8490// Initialise from Unicode string...
    85 oStringA::oStringA(LPCWSTR pUnicode)
     91oStringA::oStringA(LPCWSTR pUnicode)  : oStringBase(sizeof(char))
    8692{
    8793    long        strLen = lstrlenW(pUnicode) + 1;
    8894
    89     m_Heap = GetProcessHeap();
    90     getBuf(strLen);
     95    getBuf( strLen);
    9196    UnicodeToAscii((LPWSTR)pUnicode, m_strBuf);
    9297    m_strLen = strLen;
     
    9499
    95100// Initialise from ASCII string...
    96 oStringA::oStringA(LPCSTR pAscii)
     101oStringA::oStringA(LPCSTR pAscii)  : oStringBase(sizeof(char))
    97102{
    98103    long        strLen = strlen(pAscii) + 1;
    99104
    100     m_Heap = GetProcessHeap();
    101     getBuf(strLen);
     105    getBuf( strLen);
    102106    strcpy(m_strBuf, pAscii);
    103107    m_strLen = strLen;
     
    105109
    106110// Initialise from another oString
    107 oStringA::oStringA(const oStringA &ref)
    108 {
    109     m_Heap = GetProcessHeap();
    110     getBuf(ref.m_strLen);
     111oStringA::oStringA(const oStringA &ref)  : oStringBase(sizeof(char))
     112{
     113    getBuf( ref.m_strLen);
    111114    strcpy(m_strBuf, ref.m_strBuf);
    112115    m_strLen = ref.m_strLen;
    113116}
    114117
    115 //Destroy resources...
    116 oStringA::~oStringA()
    117 {
    118     freeBuf();
     118// Initialise from CLSID
     119oStringA::oStringA( REFCLSID pClsId)  : oStringBase(sizeof(char))
     120{
     121    getBuf( 50);        // Incl. terminator...
     122
     123    // Assign string...
     124    operator=(pClsId);
    119125}
    120126
     
    122128oStringA::operator LPSTR()
    123129{
    124     return m_strBuf;
     130    return (LPSTR)m_strBuf;
    125131}
    126132
     
    133139
    134140    // Setup new string...
    135     getBuf(string.m_strLen);
     141    getBuf( string.m_strLen);
    136142    strcpy(m_strBuf, string.m_strBuf);
    137143    m_strLen = string.m_strLen;
     
    147153
    148154    // Setup new string...
    149     getBuf(strLen);
     155    getBuf( strLen);
    150156    strcpy(m_strBuf, pAscii);
    151157    m_strLen = strLen;
     
    161167
    162168    // Setup new string...
    163     getBuf(strLen);
     169    getBuf( strLen);
    164170    UnicodeToAscii((LPWSTR)pUnicode, m_strBuf);
    165171    m_strLen = strLen;
     
    167173}
    168174
     175oStringA oStringA::operator =  (REFCLSID rClsId)
     176{
     177    // Lose old string...
     178    freeBuf();
     179
     180    // Setup new string...
     181    getBuf( 50);
     182    m_strLen  = sprintf(m_strBuf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
     183            rClsId->Data1,
     184            rClsId->Data2,
     185            rClsId->Data3,
     186            rClsId->Data4[0],
     187            rClsId->Data4[1],
     188            rClsId->Data4[2],
     189            rClsId->Data4[3],
     190            rClsId->Data4[4],
     191            rClsId->Data4[5],
     192            rClsId->Data4[6],
     193            rClsId->Data4[7]);
     194    return *this;
     195}
    169196
    170197// Add String to String
     
    215242    long        strLen = m_strLen + string.m_strLen - 1;
    216243
    217     adjBuf(strLen);
     244    adjBuf( strLen);
    218245    strcpy(m_strBuf + m_strLen - 1, string.m_strBuf);
    219246    m_strLen = strLen;
     
    227254    long        strLen = m_strLen + strlen(pAscii);
    228255
    229     adjBuf(strLen);
     256    adjBuf( strLen);
    230257    strcpy(m_strBuf + m_strLen - 1, pAscii);
    231258    m_strLen = strLen;
     
    239266    long        strLen = m_strLen + lstrlenW(pUnicode);
    240267
    241     adjBuf(strLen);
     268    adjBuf( strLen);
    242269    UnicodeToAscii((LPWSTR)pUnicode, m_strBuf + m_strLen - 1);
    243270    m_strLen = strLen;
     
    246273}
    247274
    248 
     275// ======================================================================
     276// oStringW - String manipulation based on Unicode
     277// ======================================================================
     278
     279// Initialise to nothing...
     280oStringW::oStringW( void) : oStringBase(sizeof(WCHAR))
     281{
     282    getBuf( 1); // Incl. terminator...
     283}
     284
     285// Initialise to a specified length...
     286oStringW::oStringW(int defLen) : oStringBase(sizeof(WCHAR))
     287{
     288    getBuf( defLen + 1);
     289}
     290
     291// Initialise from Unicode string...
     292oStringW::oStringW(LPCWSTR pUnicode) : oStringBase(sizeof(WCHAR))
     293{
     294    long        strLen = lstrlenW((const WCHAR *)pUnicode) + 1;
     295
     296    getBuf(strLen);
     297    lstrcpyW((LPWSTR)m_strBuf, pUnicode);
     298    m_strLen = strLen;
     299}
     300
     301// Initialise from Unicode string...
     302oStringW::oStringW(const wchar_t * pUnicode) : oStringBase(sizeof(WCHAR))
     303{
     304    long        strLen = lstrlenW((LPWSTR)pUnicode) + 1;
     305
     306    getBuf(strLen);
     307    lstrcpyW((LPWSTR)m_strBuf, (LPCWSTR)pUnicode);
     308    m_strLen = strLen;
     309}
     310
     311// Initialise from ASCII string...
     312oStringW::oStringW(LPCSTR pAscii) : oStringBase(sizeof(WCHAR))
     313{
     314    long        strLen = strlen(pAscii) + 1;
     315
     316    getBuf( strLen);
     317    AsciiToUnicode((char *)pAscii, (LPWSTR)m_strBuf);
     318    m_strLen = strLen;
     319}
     320
     321// Initialise from another oString
     322oStringW::oStringW(const oStringW &ref) : oStringBase(sizeof(WCHAR))
     323{
     324    getBuf( ref.m_strLen);
     325    lstrcpyW((LPWSTR)m_strBuf, (LPWSTR)ref.m_strBuf);
     326    m_strLen = ref.m_strLen;
     327}
     328
     329// Initialise from CLSID
     330oStringW::oStringW( REFCLSID pClsId) : oStringBase(sizeof(WCHAR))
     331{
     332    getBuf( 50);        // Incl. terminator...
     333
     334    // Assign string...
     335    operator=(pClsId);
     336}
     337
     338// Return pointer to string...
     339oStringW::operator LPWSTR()
     340{
     341    return (LPWSTR)m_strBuf;
     342}
     343
     344// Assign
     345oStringW oStringW::operator =  (const oStringW & string)
     346{
     347    // Lose old string...
     348    freeBuf();
     349
     350    // Setup new string...
     351    getBuf( string.m_strLen);
     352    lstrcpyW((LPWSTR)m_strBuf, (LPWSTR)string.m_strBuf);
     353    m_strLen = string.m_strLen;
     354    return *this;
     355}
     356
     357oStringW oStringW::operator =  (LPCSTR pAscii)
     358{
     359    long        strLen = strlen(pAscii) + 1;
     360
     361    // Lose old string...
     362    freeBuf();
     363
     364    // Setup new string...
     365    getBuf( strLen);
     366    AsciiToUnicode((char *)pAscii, (LPWSTR)m_strBuf);
     367    m_strLen = strLen;
     368    return *this;
     369}
     370
     371oStringW oStringW::operator =  (LPCWSTR pUnicode)
     372{
     373    long        strLen = lstrlenW(pUnicode) + 1;
     374
     375    // Lose old string...
     376    freeBuf();
     377
     378    // Setup new string...
     379    getBuf( strLen);
     380    lstrcpyW((LPWSTR)m_strBuf, pUnicode);
     381    m_strLen = strLen;
     382    return *this;
     383}
     384
     385oStringW oStringW::operator =  (const wchar_t * pUnicode)
     386{
     387    long        strLen = lstrlenW((LPWSTR)pUnicode) + 1;
     388
     389    // Lose old string...
     390    freeBuf();
     391
     392    // Setup new string...
     393    getBuf( strLen);
     394    lstrcpyW((LPWSTR)m_strBuf, (LPWSTR)pUnicode);
     395    m_strLen = strLen;
     396    return *this;
     397}
     398
     399oStringW oStringW::operator =  (REFCLSID rClsId)
     400{
     401    char        tmp[50];
     402
     403    // Lose old string...
     404    freeBuf();
     405
     406    // Setup new string...
     407    getBuf( 50);
     408    m_strLen  = sprintf(tmp, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
     409            rClsId->Data1,
     410            rClsId->Data2,
     411            rClsId->Data3,
     412            rClsId->Data4[0],
     413            rClsId->Data4[1],
     414            rClsId->Data4[2],
     415            rClsId->Data4[3],
     416            rClsId->Data4[4],
     417            rClsId->Data4[5],
     418            rClsId->Data4[6],
     419            rClsId->Data4[7]);
     420    AsciiToUnicode(tmp, (LPWSTR)m_strBuf);
     421    return *this;
     422}
     423
     424// Add String to String
     425oStringW oStringW::operator +  (const oStringW & string)
     426{
     427    // two terminators to account for...
     428    oStringW    product(m_strLen + string.m_strLen - 1);
     429
     430    lstrcpyW((LPWSTR)product.m_strBuf, (LPWSTR)m_strBuf);
     431    lstrcpyW((LPWSTR)product.m_strBuf + m_strLen - 1, (LPWSTR)string.m_strBuf);
     432    product.m_strLen = m_strLen + string.m_strLen - 1;
     433
     434    return product;
     435}
     436
     437// Add String to ASCII string
     438oStringW oStringW::operator +  (LPCSTR pAscii)
     439{
     440    long        strLen = m_strLen + strlen(pAscii);
     441
     442    oStringW    product(strLen);
     443
     444    lstrcpyW((LPWSTR)product.m_strBuf, (LPWSTR)m_strBuf);
     445    AsciiToUnicode((char *)pAscii, (LPWSTR)product.m_strBuf + m_strLen - 1);
     446    product.m_strLen = strLen;
     447
     448    return product;
     449}
     450
     451// Add String to UNICODE string
     452oStringW oStringW::operator +  (LPCWSTR pUnicode)
     453{
     454    long        strLen = m_strLen + lstrlenW(pUnicode);
     455
     456    oStringW    product(strLen);
     457
     458    lstrcpyW((LPWSTR)product.m_strBuf, (LPWSTR)m_strBuf);
     459    lstrcpyW((LPWSTR)product.m_strBuf + m_strLen - 1, (LPWSTR)pUnicode);
     460    product.m_strLen = strLen;
     461
     462    return product;
     463}
     464
     465// Add String to UNICODE string
     466oStringW oStringW::operator +  (const wchar_t * pUnicode)
     467{
     468    long        strLen = m_strLen + lstrlenW((LPWSTR)pUnicode);
     469
     470    oStringW    product(strLen);
     471
     472    lstrcpyW((LPWSTR)product.m_strBuf, (LPWSTR)m_strBuf);
     473    lstrcpyW((LPWSTR)product.m_strBuf + m_strLen - 1, (LPWSTR)pUnicode);
     474    product.m_strLen = strLen;
     475
     476    return product;
     477}
     478
     479// Concatenate string object
     480oStringW oStringW::operator += (const oStringW & string)
     481{
     482    // two terminators to account for...
     483    long        strLen = m_strLen + string.m_strLen - 1;
     484
     485    adjBuf( strLen);
     486    lstrcpyW((LPWSTR)m_strBuf + m_strLen - 1, (LPWSTR)string.m_strBuf);
     487    m_strLen = strLen;
     488
     489    return *this;
     490}
     491
     492// Concatenate Ascii string
     493oStringW oStringW::operator +=  (LPCSTR pAscii)
     494{
     495    long        strLen = m_strLen + strlen(pAscii);
     496
     497    adjBuf( strLen);
     498    AsciiToUnicode((char *)pAscii, (LPWSTR)m_strBuf + m_strLen - 1);
     499    m_strLen = strLen;
     500
     501    return *this;
     502}
     503
     504// Concatenate Unicode string
     505oStringW oStringW::operator +=  (LPCWSTR pUnicode)
     506{
     507    long        strLen = m_strLen + lstrlenW(pUnicode);
     508
     509    adjBuf( strLen);
     510    lstrcpyW((LPWSTR)m_strBuf + m_strLen - 1, (LPWSTR)pUnicode);
     511    m_strLen = strLen;
     512
     513    return *this;
     514}
     515
     516// Concatenate Unicode string
     517oStringW oStringW::operator +=  (const wchar_t * pUnicode)
     518{
     519    long        strLen = m_strLen + lstrlenW((LPWSTR)pUnicode);
     520
     521    adjBuf( strLen);
     522    lstrcpyW((LPWSTR)m_strBuf + m_strLen - 1, (LPWSTR)pUnicode);
     523    m_strLen = strLen;
     524
     525    return *this;
     526}
     527
     528
Note: See TracChangeset for help on using the changeset viewer.